How To Turn Off Post Revision In WordPress 2.6

One of the irritating feature for me in WordPress 2.6 is the post revision. I am the only author of my blog and hence this feature is useless to me.

Just in case you are wondering how post revision works, whenever a post is edited, a new row will be created in wp_posts table. Hence if your posts or pages got edited 10 times, you will have 10 new rows in wp_posts table.

In no time your wp_posts table will be filled up and the post ID will be huge.

To turn off this feature, add this following code to wp-config.php:

define('WP_POST_REVISIONS', false);

You can also delete all post revisions by running this query in phpMyAdmin:

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'  

Be sure to backup your database first before performing any queries in phpMyAdmin.

*UPDATE* Auto Saves does not create a revision of the post.

*UPDATE 2* Updated SQL query from Andrei Neculau as the previous query does not delete from wp_postmeta and wp_term_relationships tables.

*UPDATE 3* There is a proper way of cleaning up Post Revisions as mentioned by kitchin in Deleting Post Revisions: do NOT use the a,b,c JOIN code you see everywhere. I like his method more than the SQL query above.

1 Star2 Stars3 Stars4 Stars5 Stars (178 votes, average: 4.18 out of 5)

150 thoughts on “How To Turn Off Post Revision In WordPress 2.6”

  1. I just did it, and removed about 80 additional posts I won’t need.

    Thanks for the very clean fix!

  2. Thanks a lot, this solved a blank page error when trying to edit a post I made after the upgrade. All the other articles

  3. Same for me, thanks a lot, also it solved the blank page error when trying to edit a post and I don’t think it is very useful to have a revision of each post.
    Also my provider only gives me 100Mb of mysql space and I think with a open public blog it will rapidly got out of space.

    Thanks and bye

  4. Awesome! I have been deleting the “iframe – malware” stuff and each time I deleted a visible iframe, I was auto-saving/revisions the hidden iframe. Your just helped me “clean” my site, Thanks! Now Google will release me.

  5. Hi Lester,

    Those of us that ran the original “Delete” as recommended by Andrei Neculau would now have orphaned records in the term_relationships and postmeta tables.

    Any suggestions?

    R

  6. Thank you for this info. Post revisions consume a lot of my database space, so I have to turn it off otherwise I’ll run out of my hosting space.

  7. Hi Robert,

    No idea whether this code works, you want to try to see if it returns any results first.

    SELECT 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.id IS NULL

  8. Hi Lester,

    Thanks for responding so quickly.

    I ran the code you noted above and got the following response:

    #1054 – Unknown column ‘a’ in ‘field list’

    Just as an aside and an added benefit to turning of post revisioning and also the automatically saving of posts is the CPU savings. Since turning off both – I am no longer getting penalised by my Hosting Provider for chewing up CPU cycles. A big plus!!

    Cheers,

    R

    NB: I have been using your WP-DBManager and WP-PluginsUsed and they are tops!!

  9. Ops my bad, try this code:
    DELETE b, c
    FROM wp_term_relationships b LEFT JOIN wp_postmeta c ON (c.post_id = b.object_id) WHERE post_id IS NULL

    I tested it, it should work

  10. Hi Lester,

    You are definitely the man!!

    Touch wood but it seemed to work OK. It deleted over 6000 rows – which means there must have been a lot of “dead wood” in the DB (or I’m totally screwed). Will run a repair followed by an optimise.

    Thanks a million bro.

    R

  11. Lester,

    I spoke up too soon.

    My tags and categories seem to have screwed up!

    Yep – I run a backup with your WP-DBManager plugin every night.

    Important question: Is it possible to restore both those tables: term_relationships and postmeta individually or do I have to restore the entire DB?

    R

  12. Hi Lester,

    I just ran a restore using WP-DBManager (with fingers crossed) and all seems like its back to normal.

    Want to have another go at the SQL delete or do we leave it for now?

    R

  13. Lester,

    I want to run an SQL SELECT just to see what it comes back with before running the actual SQL DELETE.

    SELECT b, c
    FROM term_relationships b
    LEFT JOIN postmeta c ON ( c.post_id = b.object_id )
    WHERE post_id IS NULL

    I get the following error:
    #1054 – Unknown column ‘b’ in ‘field list’

    Any ideas?

    R

Comments are closed.