DEV Community

Ko Takagi
Ko Takagi

Posted on

How to bulk delete huge post data in WordPress

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)