Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I haven't set a limit to the number of revisions, which makes some of my post have more than 20 revisions, so how to delete these revisions?

By the way, I am using WPMU and have many blogs, so how to delete WordPress revisions for all my blogs?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

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);
share|improve this answer
    
You're right, this is much efficient too... posted my answer in hurry and didn't notice the WP MU part too. +1. –  deathlock Oct 16 '12 at 5:39
    
and how to remove revisions except let's say the last 3? –  Matoeil Sep 10 '13 at 12:41
add comment

There is also a plugin that can help you do this http://wordpress.org/extend/plugins/wp-optimize/

From the website:

WP-Optimize is a WordPress 2.9++ database cleanup and optimization tool. It doesn't require PhpMyAdmin to optimize your database tables.

It allows you to remove post revisions, comments in the spam queue, un-approved comments within few clicks.

share|improve this answer
    
Please describe what the plugin does and how it solves the problem. –  toscho Oct 16 '12 at 7:02
1  
There are many plugins that clean revisions and optimize without phpmyadmin; none of them are clearly stated to work with WPMU or multisite. –  songdogtech Oct 16 '12 at 13:05
    
will this plugin do harm to my database? –  hugemeow Oct 16 '12 at 13:51
    
I've used the plugin on a couple of sites I run with no issues. But it is always a good idea to backup your db first (but that is just best practise). –  darronz Oct 17 '12 at 7:42
add comment

To delete all of your Wordpress revisions, you could use this query:

DELETE FROM wp_posts WHERE post_type = "revision";

share|improve this answer
    
i have more than 100 blogs on wpmu, so i should run DELETE FROM wp_n_posts WHERE post_type = "revision"; for n times ,right? but this is quite boring:( –  hugemeow Oct 16 '12 at 13:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.