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:

1
define('WP_POST_REVISIONS', false);

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

1
2
3
4
5
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.

Tags: , ,

Email This Post Email This Post Print This Post Print This Post

1 Star2 Stars3 Stars4 Stars5 Stars (156 votes, average: 4.13 out of 5)

 

150 Responses to “How To Turn Off Post Revision In WordPress 2.6”

  1. Lester Chan says:

    @oldengine Thanks, I have updated the code.

  2. One small correction I’ve made just now –
    DELETE a,b,c

  3. Lester Chan says:

    Thanks updated =D

  4. zer0day says:

    :o Didn’t realize it was on by default, thanks for post.

  5. [...] finally, Lester Chan offers a way to delete the revisions that have already been [...]

  6. Mix says:

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

    Thanks for the very clean fix!

  7. [...] points to good advice from Lester Chan to ensure that you don’t fill up your wordpress revision [...]

  8. StevyGee says:

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

  9. Jo Bench says:

    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

  10. [...] que vi em dois sites (primeiro e segundo) pode-se facilmente desabilitar a revisão de posts adicionando a linha abaixo no arquivo [...]

  11. [...] información la he sacado fundamentalmente de esta web y juraría que también se habló de ello en Ayuda Wordpress, pero me ha sido imposible encontrar [...]

  12. Hirvine says:

    Thanks was looking for the option. Just wanting to mention the post is highly appreciated.

  13. [...] WordPress guru Lester Chan found a way. An edit to the wp-config file turns off post [...]

  14. [...] a database full of revisions, you can get rid of them. Lester Chan outlines a nice and easy way to remove the old revisions from your [...]

  15. Phew! You just saved my day with this hack.

  16. just browsing says:

    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.

  17. [...] How To Turn Off Post Revision In WordPress 2.6 is the answer to how to disable. To turn it off, add the following code to [...]

  18. Robert@PNG says:

    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

  19. hamdan says:

    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.

  20. Lester Chan says:

    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

  21. Robert@PNG says:

    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!!

  22. Lester Chan says:

    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

  23. Robert@PNG says:

    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

  24. Lester Chan says:

    Hi Robert,

    I hope you did a backup before you ran the code just in case :)

  25. Robert@PNG says:

    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

  26. Robert@PNG says:

    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

  27. Lester Chan says:

    I just tested on my localhost, it seems to work fine. What version of MYSQL u are using?

  28. Robert@PNG says:

    I’m with Bluehost and they run V5.0.51a

    R

  29. Robert@PNG says:

    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