This article introduces how to display and edit a list of WordPress posts using WP-CLI. The method to display a list of posts can be easily confirmed using WP-CLI. Posts can be edited using the vi editor with WP-CLI.
Checking Posts
You can check the list of posts.
The following example displays the “title, publish status, and ID” of each post.
- Regular Pages
wp post list --post_type=post --fields=post_title,post_status,ID - Static Pages
wp post list --post_type=page --fields=post_title,post_status,ID
Editing Posts
Put the post ID in the “ID” option. Do this after confirming the ID in the post list.
wp post edit ID
Post editing uses the “vi editor”.
vi Editor
$ vi memo.txt
- i Change from command mode to input mode - ESC Change from input mode to command mode. - :wq in command mode Save and exit - :q! in command mode Exit without saving
- :w Overwrite and save
- :w filename Save file with a different name
- :wq filename Save file with a different name and exit