How to Create Dummy Posts with WP-CLI

How to Create Dummy Posts with WP-CLI

When building a website, you might need to create dummy posts to see how the site looks once it has content. To do this, you can use a plugin or create dummy posts with WP-CLI, which we will cover in this tutorial.

How to Create Dummy Posts with WP-CLI

Before starting the tutorial on creating dummy posts with WP-CLI, make sure your server has WP-CLI installed. If not, you can follow this tutorial: How to Install WP-CLI on Linux.

Additionally, ensure you are inside the WordPress installation folder path on your server to run WP-CLI commands, as this page only covers the list of commands you will use.

1. Creating Default Dummy Posts

By default, you can use the wp post generate command to create random posts on your website

wp post generate

However, if you use the command above, the system will create 100 empty posts with titles from Post 1 to Post 100. This might be too many, and when you open the post page, the content will be empty.

2. Creating Posts with a Specific Count

To create a specific number of posts, for example 5 posts, you can use the --count parameter

wp post generate --count=5

3. Creating Dummy Content for Pages

If you use wp post generate by default, it creates dummy content for posts rather than pages. You can use the parameter --post_type to create dummy content for Pages

wp post generate --post_type=page

4. Creating Posts with a Specific Title

Because the default title format used if you do not define one is Post n, you can use the parameter --post_title. For example, to create posts with the title Lorem Ipsum, you can use this command

wp post generate --count=5 --post_type=post --post_title="Lorem Ipsum"

5. Creating Posts with Content from Another Website

If you want to create dummy posts with content from another website using the STDIN system, you need to use CURL, for example

curl -N https://pastebin.com/raw/MU32LcR0 | wp post generate --count=5 --post_content --post_type=post --post_title="Lorem Ipsum"

6. Creating Posts with a Specific Author

With all the previous commands, each piece of content does not have an author. If you want to add an author, you can add the parameter --post_author= where the post author here needs to be filled with the author's username

curl -N https://pastebin.com/raw/MU32LcR0 | wp post generate --count=5 --post_content --post_type=post --post_title="Lorem Ipsum" --post_author=wpgan-cli

Those are the commands you can use to create dummy content in WordPress with WP-CLI. For the complete command, you can use the example in number 6 (Creating Posts with a Specific Author) because the command example is complete by that point.

For other parameters that can be used to generate posts, you can read about them on the official WordPress page here: https://developer.wordpress.org/cli/commands/post/generate/

Written by

Muhammad Khoirun Nasikin

I enjoy tinkering with WordPress, hosting, VPS, web development, and various small experiments related to websites. I have over 3 years of experience in the web hosting industry.

COMMENTS

Loading...