How to disable and delete post revisions in WordPress

SunFlower: the Fibonacci sequence, Golden SectionThis is a very old trick that was repeated over and over again but still very few people seems to acted on it.

If you are not using post revisions (and if you do not know what they are, chance is you are not) I wholeheartedly recommend that you disable them and also remove all traces of them from your database.

In recent optimization work we did, I found tens of thousands of post revision records which related to 150MB of database space used on one and 60MB on the other site. Not only it's making your database clunky and slow but you are paying a price for a feature most users simply do not use. When this happens on high traffic site you are probably paying double price.

Time for action!

First step, disable post revisions. Edit your wp-config.php (WordPress configuration file, found in the root of your WP installation) and add this line:

define('WP_POST_REVISIONS', false);

Secondly we need to delete post revisions and associated data that is already in the database. So you will need access to your DB, either through command line 'mysql' or better with phpMyAdmin interface.

Select your database and execute this query:

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'

This will remove all revision posts and associated objects from the database. I recommend running OPTIMIZE tables command after (in phpMyAdmin just mark all tables and select Optimize) to compact your database. And that's all folks.

More like this:

Posted in: WordPress
TAGS:, , , , , , , , , , , , , , ,
Both comments and trackbacks are currently closed.


  1. Aaron
    Oct 18th, 2012 6:10 AM

    awesome stuff -- 5 mins just sped my site up instantly.

  2. May 22nd, 2012 2:48 PM

    Thanks for this, we turned of the post reviosns feature but then found that you can limit it also , so we set it to 5

  3. Dec 8th, 2011 6:36 PM

    After reading this post, I wanted to delete all of those post revisions, but honestly, I'm not a programmer although I can make due most of the time. I was grateful to see that there is a plugin that does this for you. Thanks to @Omar for sharing that. Ive already installed, activated, and run the plugin. Now, my database has been optimized and I've saved 5MB of space. Thanks guys!

  4. Feb 16th, 2011 4:03 PM

    nice trick mate uu help me to remove my WP-Optimize plugin :)

  5. Dec 2nd, 2010 11:21 PM

    Thanks Vladimir - I do have client's that use the revisions feature to get back to a point before they messed their post up. What would be helpful is a function to only keep the last 10 revisions. Once a revision hits the number 11 spot, it is deleted. How would you do this? MAny thanks

    • Dec 2nd, 2010 11:26 PM

      Hi Nik,

      To limit the number of revisions, do this:
      define('WP_POST_REVISIONS', 3); // alter number of post revisions kept.

      ...and change the 3 to 10 for your example.

      • Dec 2nd, 2010 11:30 PM

        1-800-WPMODDER :)

      • Dec 3rd, 2010 12:34 AM

        Great stuff - thanks Adam. I subscribed to the feed on you site as well :)

        • Dec 3rd, 2010 3:29 PM

          @Vladimir - I was in customer service before web development. I would feel guilty knowing the quick answer and not sharing it, especially after all the knowledge and help I've received from fellow WordPress community members like yourself:)

          @Nik - You're welcome, and thanks for subscribing!

  6. Dec 2nd, 2010 4:10 PM

    Good stuff Adam. Does anyone have a query to remove extra term and meta records after all post revisions have already been removed ?

  7. Dec 2nd, 2010 3:21 PM

    Nice tip, especially the database cleanup. I wrote something similar here with a couple extra lines you can add if you want to keep the post revisions but limit the time between saves and the number of revisions available.

    define('AUTOSAVE_INTERVAL', 120 ); // seconds (default is 60)
    define('WP_POST_REVISIONS', false ); // disable post revisions
    define('WP_POST_REVISIONS', 3); // alter number of post revisions kept.

  8. Dec 2nd, 2010 3:17 PM

    You make codings sound easy for some of the "dabblers" around here :) Good luck mr.Prelovac!

  9. Dec 2nd, 2010 1:28 PM

    useful tips, thanks. You can also use the WP-Optimize plugin that enables both cleaning revisions and optimizing db tables. It also displays the status of each.

  • ManageWP