How to delete post revisions?

This is a much safer query to use and will remove related entries from the postmeta and term_relationship, unlike deathlocks query in his answer.

Change the {id} to the id of each blog posts table. You can combine this query to run all the post tables at once, but try this on one table first. I’ve used it many times on single WP installs.

DELETE a,b,c
FROM wp_{id}_posts a
LEFT JOIN wp_{id}_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_{id}_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type="revision"

After you run it, optimize the database in phpmyadmin.

And add this line near the top of wp-config.php to prevent future revisions:

define('WP_POST_REVISIONS', 0);

or save one revision:

define('WP_POST_REVISIONS', 1);

Leave a Comment