brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: wp post list --post_status=draft shows your unpublished posts

WordPress
~/tips/tip-wordpress-wp-post-list-drafts

wp post list --post_status=draft

Lists draft posts from the command line with the fields and output format you choose.

Before cleaning up a blog, I want to know what is sitting around unpublished. WP-CLI answers that without opening the admin.

wp post list --post_status=draft
wp post list --post_status=draft --fields=ID,post_title,post_date
wp post list --post_status=draft --format=ids

--post_status filters by status. The default is any, which covers every status that is not excluded from search. Trashed and auto-draft posts only show up if you ask for them by name, such as --post_status=trash.

--fields limits the columns. The default fields are ID, post_title, post_name, post_date and post_status, and others such as post_author and post_modified are available. --format can be table, csv, ids, json, count or yaml, so --format=count tells you how many drafts there are.

The command also accepts WP_Query arguments, so you can combine filters, for instance with --author=2.

The caveat is the post type. The default is post, so drafts of pages or custom post types do not appear until you add --post_type=page, or a comma separated list such as --post_type=post,page. If you then pipe the ids into a delete command, check the list first, because deleting posts is not something you can undo without a backup.

Further reading: WP-CLI: wp post list

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link