Generate dummy posts, comments, terms or users

An overview of the commands WP-CLI includes to generate test content and users.

Producing sample content for your WordPress site can be an arduous task through the WordPress admin.

Fortunately, WP-CLI comes with several commands to automatically generate test content and users:

  • wp post generate (doc) – Generate dummy posts for one or more post types. Optionally provide a status, author, date, or post content to be applied to each post. By default, these will be posts published on the current date with title "Post 123", where "123" is the number of the post created.
  • wp comment generate (doc) – Generate dummy comments. Optionally provide a post id to assign the comments to.
  • wp term generate (doc) – Generate dummy terms for a specific taxonomy.
  • wp user generate (doc) – Generate dummy users. Optionally provide a role to be applied to each user. By default, users will have the current WordPress role.

Each command also includes a --count=<count> argument to give you control over the number of items to be created.

$ wp post generate --count=10
Generating posts  100% [==================================] 0:01 / 0:10
$ wp post list --format=count

You may notice these commands are a lower-level implementation of data generation. They’ll create new rows in the database for you, but won’t necessarily produce all of the attributes you may need for an individual item. For instance, if your site is heavily visual, you may want to assign a thumbnail image to each generated post.

The RESTful WP-CLI project is working on an abstraction to generate dummy content through a higher level understanding of the data your WordPress site expects. For instance, if you have a product custom post type, being able to generate a dummy price, SKU, and availability count, in addition to the product title. Until this higher-level abstraction exists though, it’s impossible to produce a general purpose tool that works with WordPress sites of all shapes and sizes.