loading...

How to bulk delete huge post data in WordPress

ko31 profile image Ko Takagi ・1 min read

That's a lot of work, deleting hundreds of thousands of huge post data.

Let's use the WP-CLI command to delete all those data at once.

How to use

Bulk delete all post data.

wp post delete $(wp post list --post_type='post' --format=ids) --force

If you want to delete data from your custom post type, you can specify the post type in the post_type option

# Delete post type 'news'
wp post delete $(wp post list --post_type='news' --format=ids) --force

If you have too much data to delete, you may get an Argument list too long error.

In that case, you can delete it little by little with a shell script like the following.

#!/bin/sh

# Deleting 10,000 at a time.
for i in `seq 1 10`
do
    wp post delete $(wp post list --post_type='your-post-type' --format=ids --posts_per_page=10000) --force
done

echo "done"

Posted on by:

ko31 profile

Ko Takagi

@ko31

I am freelance web engineer in Japan. Since I am studying English, I started writing articles here😆 I want to play catch! ⚾️

Discussion

markdown guide