Whenever I need to do anything “bulk” in WordPress, I do this with WP CLI. It’s just a smarter, faster, and more performant way of doing things. Bulk deleting posts in WordPress with WP CLI then becomes a super simple exercise.
Time needed: 1 minute
Bulk delete posts in WordPress with CLI works like this:
- Open up terminal on your machine
I’m using iTerm2 on my Mac, but any terminal app will do. Log into your server and navigate to the folder where your WordPress installation is living. Your WordPress webhost will have instructions on how to do that. If not, find a better host.
- Paste the following command
This command will delete all the posts in your WordPress installation:
wp post delete $(wp post list --post_type='post' --format=ids) --force
That last part,
--forcewill delete your posts permanently. So, be carefull. You won’t be able to fish them out of the trash.
- Do this if you want to delete another custom post type
If you want to bulk delete a particular custom post type, you change the
--post_type='post'to whatever the name of that custom post type is. For example, if you want to delete all post types entries in your “book” post type, the command would change to:
wp post delete $(wp post list --post_type='book
' --format=ids) --force
- Do this if your want to bulk delete posts on a subsite inside your WordPress multi-site
If you want to bulk delete on a subsite of your WordPress netwerk, you’ll need to make sure the
wp post listpart knows it needs to do its work in that subsite context as well as the
wp post deletepart.
Your command will then look like:
wp post delete $(wp post list --post_type='book' --format=ids --url=example.com) --force --url=example.com
- Hit Enter
After pasting whatever version in your terminal, just hit enter. WP CLI will take care of the rest.
That’s it. Let me know if you’re running into any issues. I’d love to help.