Delete WordPress old revisions

WordPress stores revisions of the posts, pages, etc. while you write them. Without even knowing you may have about 5 or more revisions of each entry. And each revisions represents one entry in your posts database table with post_type column as revision.

revisions

The first thing I thought was to simply delete those old revisions that had post_type equals revision:

DELETE * FROM wp_posts WHERE post_type='revision';

Then, just in case, I did a search and found out I was not completely right. As Ozh explains here:

Note that the above SQL query just deletes post marked as revisions. If for some reason you associated a revision with a tag or a category that was then removed when the final post was published, you will have extra entries in other tables such as terms.

The query then should look like this:

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

Note: use your table prefix and make a backup first just in case!

You may also disable the revision feature (but I wouldn’t recommend it) in the wp-config.php file:

define('WP_POST_REVISIONS', false);

Or just limit the amount of revisions to a fixed number:

define('WP_POST_REVISIONS', 5);

Ref: http://weblogtoolscollection.com/archives/2010/09/28/deleting-wordpress-revisions/

You might also like

Remove a WordPress action in child theme
If you want to remove a WordPress action that was added in the parent theme like this:function...

Exit maintenance mode in WordPress when an update fails
To exit maintenance mode in WordPress when an update fails is as easy as deleting the .maintenance file...

Fix plugins and themes installation when WordPress asks for FTP credentials
When WordPress doesn't have the right premissions on the wp-content folder it will ask for your FTP credentials...

Change WordPress table prefix to avoid SQL injection attacks
WordPress uses a table prefix for each installation in case you want/need to have more than one WordPress...

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.