Occasionally I find myself needing to quickly create a series of posts or pages—for building out a basic skeleton of a site, or for quickly populating content. Manually doing this within the WordPress dashboard can be tedious. This is where WP-CLI can save the day. In this post, I’ll look at how to use WP-CLI to quickly generate a series of posts within WordPress.

WP-CLI is a powerful tool that can be used to perform various tasks related to your website. For example, you can create new posts using the wp post create command:

The command is limited to creating a single post at a time. However, we can run multiple commands at once by separating them with a semicolon. So if we wanted to create two blog posts about one of the best Thai restaurants in London, we could run this command:

In order to make the above even easier, I wrote a handy tool that generates the command for you.

This tool is simple, but useful for quickly generating a small number of posts. With more time, a short bash script could loop through an array and perhaps support hierarchical post structures. For my purposes, this was sufficient and I wanted to share it in the hope that other people find it useful.