Can I use wp-cli to create posts with a custom post types?

I regularly need to create a batch of posts of a custom post type, with names and meta values that follow a regular pattern. This seems like a perfect canditate for using wp-cli, but so far it hasn't worked.

Using wp-cli, if I enter:

wp post create --post_title='test' --post_status='draft' post_type='class_notes'

I get an error:

Unable to read content from 'post_type=class_notes'.

However wp-cli is definitely able to connect to this post type, as the following returns a proper list of labels and capabilities:

wp post-type get 'class_notes'

Is it the case that I simply cannot create a post with a custom post type using wp-cli?

Topic wp-cli Wordpress

Category Web


You can also use https://developer.wordpress.org/cli/commands/post/generate/ to generate how posts you need (for testing purpose for example)


It should probably be

wp post create --post_title='test' --post_status='draft' --post_type='class_notes'

(note the two -- that mark it as a command option)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.