In our last article we went thru some wp-cli usage examples and got a bit familiar with the wp-cli tool. In this article we will see how we can manage our posts using the wp-cli tool.
wp post <command
SUBCOMMANDS
create Create a post.
delete Delete a post by ID.
edit Launch system editor to edit post content.
generate Generate some posts.
get Get a post's content by ID.
list Get a list of posts.
meta Manage post custom fields.
term Manage post terms.
update Update one or more posts.
aodba451@sgp25 [~/www]# wp post list
aodba451@sgp25 [~/www]# wp post --user=1 list
aodba451@sgp25 [~/www]# wp post create --post_status=publish --post_title="Test AO Post" --edit
Success: Created post 5475.
aodba451@sgp25 [~/www]# wp post edit 5475
Warning: No change made to post content.
export EDITOR=vim
aodba451@sgp25 [~/www]# wp post delete 5475 --force
Success: Deleted post 5475.
aodba451@sgp25 [~/www]# wp post delete $(wp post list --post_status=trash --format=ids)
Success: Deleted post 5223.
aodba451@sgp25 [~/www]#wp post update 5477 --post_name='New Name Post' --post_status=publish
Success: Updated post 5477.
aodba451@sgp25 [~/www]# wp post update 5477 --post_title="New Title Post"
Success: Updated post 5477.