Full Stack Web Developer


Remove post revisions using WP CLI

I found wp-cli really helpful when dealing with Database, and removing post revisions is one of them.

Ads: Register now via this link to receive $100 credit from Vultr

I experienced a page load problem when working with Block block-based theme. For Blocks that have complex layouts, the site generates heavy revisions in the database that kill the page load at the website admin.

I then came up with the idea of removing the post revisions and removing them via WP-CLI is the fastest and easiest approach.

Before doing this, I would recommend backing up the database first.

The following command will move all revisions to the trash:

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

And to remove them completely from the website, use the following command:

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

Notice the flag –force.

That’s it!


Leave a Reply

Your email address will not be published. Required fields are marked *