Featured Image How to Delete WordPress Post Revisions the Correct Way

How to Delete WordPress Post Revisions the Correct Way

Cabe Nolan Author
Cabe Nolan November 20, 2018


This post was originally created on our sister site WP Cover.
View Original Article

WordPress post revisions is a great feature that comes built into WordPress.  It allows us to quickly backtrack to a previous version of a post, page or custom post type if we make a mistake while editing.

At the same time, if not regularly monitored, post revisions can cause your database to increase is size drastically and as a result slow down your site.  People have posted lots of tutorials on how to delete post revisions and unfortunately most of them are the same and NOT the correct way to complete a cleanup.  Some of these sites that publish these tutorials are big name WordPress sites and should be ashamed to share blatantly wrong information.  There are also numerous plugins that claim to delete revisions.  I can’t comment on whether these plugins do it the right or wrong way so my advice would be to follow the instructions below.

All around the internet, you’ll find this basic SQL statement that you should run to delete post revisions:

DELETE FROM wp_posts WHERE post_type = "revision";


While the above statement will clear out just the post revisions, it doesn’t delete all the other data that is stored along with the post such as post meta and taxonomy relationships. In today’s modern development world, most post meta tables are larger than the post table so simply deleting revisions from the post table does not even tackle the main component of your database bloat. Here is the correct SQL statement you should run:

DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision'

The above statement will delete the data from the posts table, post meta table and the term relationships table effectively clearing all data associated with post revisions.

This is another example why you always need to remain on your toes and don’t simply copy and paste tutorials even when they are from well known WordPress publishers. There’s a lot of bad information floating around out there on WordPress. Don’t fall victim to it!

Save this correct information and bookmark this page so you can start cleaning up your revisions the right way!

The post How to Delete WordPress Post Revisions the Correct Way appeared first on WP Cover.


Cabe Nolan Author Image
Written by

Cabe Nolan