Bulk delete posts in WordPress with WP CLI (+variants)

Home » Bulk delete posts in WordPress with WP CLI (+variants)

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.

Here’s How

Time needed: 1 minute

Bulk delete posts in WordPress with CLI works like this:

  1. 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.

  2. 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, --force will delete your posts permanently. So, be carefull. You won’t be able to fish them out of the trash.

  3. 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

  4. 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 list part knows it needs to do its work in that subsite context as well as the wp post delete part.

    Your command will then look like:
    wp post delete $(wp post list --post_type='book' --format=ids --url=example.com) --force --url=example.com

  5. 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.

First name
This field is for validation purposes and should be left unchanged.

Automatically sent to your inbox, just like 🪄