Best Practices For Prompting CodeWP

CodeWP is an AI Code Generator for WordPress. In this article, we'll be taking a look at how to prompt CodeWP for the best generations possible. Prompting any generative AI is more of an art than a science, and this fact rings true with CodeWP. It's important to be descriptive, clear, but also simple with […]
calendar_today
Published: November 25, 2022
Founder & CEO
AI Tools For WordPress Creators
Code, learn, troubleshoot, and secure WordPress sites with the CodeWP platform and our custom AI.
Start for Free

CodeWP is an AI Code Generator for WordPress. In this article, we'll be taking a look at how to prompt CodeWP for the best generations possible.

Prompting any generative AI is more of an art than a science, and this fact rings true with CodeWP. It's important to be descriptive, clear, but also simple with your prompts, while tailoring them to your desired outputs.

The concepts covered in this article can be applied to any of the modes that CodeWP has, but are primarily tailored towards the general WordPress PHP mode (set by default when you load the generator). However, a caveat that should be noted: our modes are ever improving, evolving, and changing. Over time, more basic prompts may yield the same results as more explicit and descriptive prompts, simply due to the nature of Machine Learning and Artificial Intelligence. To help expedite this, be sure to rate all of your generations!

Also, you can completely ignore everything in this article and try out your own methods. The underlying AI for CodeWP is massive and different approaches may yield great results for individual situations.

Before Prompting

Before you enter your prompt, think about what you're actually trying to do.

It's important not to stuff to much into a single prompt. Instead of asking for a snippet that makes a new post type of user_profile with 12 custom fields being filled out, and elevating the user to the editor role, and sending an email and etc..., break each objective into a single request. Then you can tie it all together by prompting:

Run the functions "cwpai_new_post, cwp_ai_upgrade_user, cwpai_update_profile, etc..." when any user registers.

Remember, this tool is designed to make you Code Snippets, not plugins and software 😃.

Prompts With Desired Outputs

Querying

Generating complex queries for WordPress is easy with CodeWP AI.

Prompt:// Get all posts published by users with the role of editor, with the post type of post page or snippet, with the tags of "tag_one" OR "tag_two", with the category of "category_good", that have been published in the past 3 months, but modified in the past 20 days, and then order by the modified date.

[cai snippet_id="1374"]

You can see that the CodeWP AI can chew through this prompt pretty easily. For those that need to create complex queries all the time, this can be a massive time saver. Let's break down this prompt:

  • Get all posts
  • published by users with the role of editor
  • with the post type of post page or snippet
  • [...]
  • and then order by the modified date

Each query parameter is separated by commas. At the end of the prompt, we have a period. Tags and categories are wrapped in quotations. For queries, doing it all in one sentence typically works best. The final "command" (for this it's "order by the modified date"), should start with "then".

Now, for queries, we can actually go for multiple steps in one prompt (contrary to what was mentioned in the section above) if we want to take the data and output it some way.

Prompt:// Get all posts published by users with the role of editor, with the post type of post page or snippet, with the tags of "tag_one" OR "tag_two", with the category of "category_good", that have been published in the past 3 months, but modified in the past 20 days, and then order by the modified date, then return the first 5 words of all queried post titles in a comma separated list.

[cai snippet_id="1375"]

We can even make this a shortcode:

Prompt:// A shortcode called "post_output" that gets all posts published by users with the role of editor, with the post type of post page or snippet, with the tags of "tag_one" OR "tag_two", with the category of "category_good", that have been published in the past 3 months, but modified in the past 20 days, ordered by the modified date, and shows them as a HTML list.

[cai snippet_id="1387"]

Notice that this prompt is one continuous flow of logic - that's important! Also, we've changed around some of the language; a shortcode THAT [query command] and THEN [does something with the data].

Shortcodes

As you can see above, you can also prompt for shortcodes. The best way to do this is to follow this template: A shortcode (called [name]) THAT does something and THEN outputs something. Here's an example:

Prompt:// A shortcode called "total donations" that gets the total dollar amount of sales for WooCommerce products with the category of donation and displays it.

[cai snippet_id="1388"]

We can also prompt for arguments/parameters, like so:

Prompt:// A shortcode that accepts a comma separated list of post ids, and shows the first 10 words of each post's excerpts, hyperlinked to the post, in a html list using.

[cai snippet_id="1392"]

General WordPress Things

We can also generate basic things like post types:

Prompt:// register a custom post type for "locations", and add custom fields for "address", "website" and "hours" to that post type.

[cai snippet_id="1397"]

You can see that we can merge multiple common things into one prompt, and CodeWP will handle it well.

Taxonomies:

Prompt:// Register a taxonomy called "Area" and add it to the post type "location"

[cai snippet_id="1401"]

Simple and easy. Also, no need to manually create all of the labels!

Custom fields:

Prompt:// Add 2 meta fields called "Editor" and "Favorites" to posts

[cai snippet_id="1399"]

Typically this will include code to add meta boxes as well.

Custom user roles:

Prompt:// Add a new user role called "members"

[cai snippet_id="1398"]

Adding/Doing Things

The general WordPress model won't be accurate for most plugins, so it can't really be prompted to do something like "when a user registers, add them to Mailerlite and send a Slack message to the channel XXXXX". However, it will do things like:

Prompt:// change the user role to Editor if they have published over 5 articles

[cai snippet_id="1402"]

When it comes to WordPress-core specific things, the sky is your limit.

Prompt:// Require users to enter a referral code called "codewp_invite" when registering and if code isn't entered, or is not "codewp_invite", show a message "beep beep boop boop: not allowed".

[cai snippet_id="1406"]

When You're Not Sure

Iterate on your prompts. If:

Prompt:// Require users to enter a referral code

Doesn't work, try:

Prompt:// Require users to enter a referral code called "codewp_invite"

And if that doesn't work, add on:

Prompt:// Require users to enter a referral code called "codewp_invite" when registering and if code isn't entered, or is not "codewp_invite", show a message...

You get the idea.

Just remember, when iterating, be sure to downvote the ones that you don't like, and upvote the ones that you do.

You can also use the Inverted Pyramid approach, which is used by salespeople to help iterate the prompt.

Conclusion

We hope that this article helps you create better prompts, and in turn, better generations when using CodeWP. It should also give you a good overview of the capabilities that the general WordPress PHP mode has, as well as some ideas of what you can use CodeWP AI to generate for your WordPress Projects.

About The Author
James LePage
Founder & CEO
More By James LePage
James LePage is an entrepreneur and founder of CodeWP, an AI platform for WordPress creators. With nearly a decade of experience founding startups and leading development agencies, James is focused on leveraging AI research and natural language processing to build smart solutions that make WordPress website creation efficient. As founder of CodeWP, James is dedicated to eliminating tedious developer searches and expensive hiring so anyone can build complex WordPress solutions easily. His technical expertise and passion for innovation drive CodeWP’s mission to serve WordPress creators globally with advanced AI capabilities.
More
Tags
Prompting

More Reading

Make WordPress Easy With AI
© WPAI, Inc. 2024 | d.b.a CodeWP