WordPress tip: Get rid of unused post revisions

March 9, 2010 at 11:58 am

WordPress have a feature which saves various copies of your posts in order to allow you to compare revisions or restore an older version of your posts. This is very useful, but it also take a lot of space in your database. Here is a very handy SQL query that will instantly delete all posts revisions as well as meta associated with it.

Just run the following query on your WordPress database, and all revisions (As well as meta associated with it) will be deleted from your database.
Of course, do not forget to make a backup of your database before running the code.

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

If you’d like to see more SQL queries for WordPress, make sure to read this post.

Thanks to One Extra Pixel for this cool query!

Tags: