How to Delete WordPress Post Revisions the Correct Way


About The Author
Cabe Nolan is the founder of WP Cover where he shares his insight into WordPress, development, & entrepreneurship. Outside of WPCover, Cabe continues to run a successful WordPress development firm, Bold City Design as well as a few high profile websites, Arrivala, Two Way Resume, Dock Skipper, and a successful outdoors brand, DolfinPack.







How to Delete WordPress Post Revisions the Correct Way

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";

DON’T DO IT

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!


Comments:

Share Your Thoughts

Leave a Reply

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


Related Stuff You Might Like







WordPress News, Tips, & Code Snippets

Join the WP Cover mailing list and get wordpress news, tips, code snippets, security warnings, and more delivered right to your inbox.  We won't flood your inbox, newsletters typically go out every 1-2 weeks unless it involves an important security release.

You have Successfully Subscribed!