60Web60

Managing posts and content with WP-CLI

WP-CLI2 min read·

WP-CLI post commands let you list, create, update, and delete WordPress posts and pages from the terminal. This is useful for bulk operations, content audits, and fixing post status issues that would be tedious through the WordPress dashboard.

Command reference

CommandWhat it does
wp post listLists posts (defaults to published posts)
wp post list --post_type=pageLists pages instead of posts
wp post list --post_status=draftLists all draft posts
wp post list --post_status=trashLists posts in the Trash
wp post list --fields=ID,post_title,post_statusLists posts showing only specific fields
wp post get <id>Shows full details of a specific post by ID
wp post create --post_title='Test' --post_status=draftCreates a new draft post
wp post update <id> --post_status=publishChanges a post's status to published
wp post delete <id>Moves a post to the Trash
wp post delete <id> --forcePermanently deletes a post (bypasses Trash and cannot be undone)
wp post meta get <id> <meta-key>Gets a specific piece of post metadata
wp post meta update <id> <meta-key> '<value>'Sets a post metadata value

Bulk-deleting spam posts

If your site has accumulated spam posts, you can list and delete them all at once.

  1. List posts in spam status to review them:
wp post list --post_status=spam
  1. If you are satisfied these should all be removed, delete them permanently:
wp post delete $(wp post list --post_status=spam --format=ids) --force

Warning about permanent deletion

The --force flag permanently deletes posts, bypassing the Trash. Without --force, posts are moved to the Trash instead, which is safer and allows recovery. Always use without --force unless you are certain you want permanent deletion.

Need help?

If you have questions about managing posts and content, visit our support page or email hello@smarthost.ie.

Frequently asked questions

How do I list all my pages instead of posts?

Add --post_type=page to your command. For example: wp post list --post_type=page.

What is the difference between wp post delete and wp post delete --force?

Without --force, the post moves to the Trash and can be recovered. With --force, it is permanently deleted and cannot be recovered.

Can I create a page with WP-CLI?

Yes. Use wp post create --post_title='My Page' --post_type=page --post_status=publish to create and publish a page immediately.

Last updated: 25 March 2026

Still need help?

Contact our support team for personalised assistance.

Contact Support