Disabling WordPress Post Revisions

WordPress is not a wiki. In other words, it’s very likely that you’re the only one who can edit your posts. It isn’t very likely someone will swoop in to wipe out or deface your content.

Multi-author blogs are a different scenario altogether, but for this, let’s assume your authors are trustworthy.

With WordPress 2.6, a new feature was introduced: post revisions.

What this means is that WordPress is watching your back. When you edit your posts, WordPress saves copies of your posts. If you fudge an edit, you can quickly choose to restore a past revision and undue the damage.

But what if that level of protection isn’t needed? What if you don’t like the idea of numerous post revisions being saved on all of your posts in your database? The data can quickly add up: I recently deleted all post revisions from another site, and by doing so I freed up nearly one megabyte of space.

Revisioning Nuked

Confident in your post management abilities? If so, you don’t need the dead weight of post revisioning needlessly draining your server resources.

Am I describing you? If so, what you need to do is simple enough:

  • Download & open for editing your wp-config.php file. This is the same file most of you would have edited when installing WordPress initially; it contains your database credentials.
  • There is a line in the file that looks like this:
    /* That's all, stop editing! Happy blogging. */

    Find it, and before it, add this line:

    define('WP_POST_REVISIONS', false);
  • Save the file, and re-upload it. No more post revisions!

Simple, eh?

Revisioning Cleanup

If you’ve been blogging for a while, your database is likely riddled with post revisions. I assume you’ll want to nuke them as well, but what can you do?

You’ll need to execute an SQL command upon your database. If your host provides you access to phpMyAdmin, you may run the command via it. Otherwise, you’ll need to use a shell connection to your database or make use of WP-DBManager, a WordPress plugin which allows you to manage your database in a variety of ways.

Prior to running any commands on your database, ensure you have a full backup of your database available. Don’t let a database disaster catch you unprepared!

Here is the command you need to run:

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';

There are three instances of wp_ in that command; you will need to replace it with whatever your table prefix is. If you forget, you can check out $table_prefix in the wp-config.php file from earlier; whatever it is set to is the prefix you will need. Special thanks to Andrei Neculau for the database command.

Running the query will delete all of your post revisions, including all meta data associated with the post, leaving you with a cleaner, smaller database. This is definitely A Good Thing™.

Revisioning Records

Maybe you don’t want to disable revisioning altogether; that’s respectable. It’s hard to deny that having past revisions could come in handy, especially, as I said earlier, on a multi-user blog where others may have access to edit your content.

However, what if you want to tug on the reins a bit, controlling just how many revisions are stored per post. By limiting the number of revisions WordPress saves, you prevent your database from becoming a disk space hog.

For instance, you can set WordPress to save only three revisions. After a post has three revisions saved, the fourth revision will cause the first to delete. Only the most recent three revisions will be saved.

To implement this, follow the same instructions as earlier for disabling revisions.

Instead of the code given earlier, you’ll want to add this line to wp-config.php:

define('WP_POST_REVISIONS', 3);

Note that the code is largely the same, except instead of setting WP_POST_REVISIONS to false, we are setting it to 3, which tells WordPress to save the three most recent revisions. Change 3 to whatever positive integer you want, and that’s how many revisions per post will be saved.

Leave a Comment

Your email address will not be published. Required fields are marked *

Use your Gravatar-enabled email address while commenting to automatically enhance your comment with some of Gravatar's open profile data.

Comments must be made in accordance with the comment policy. This site uses Akismet to reduce spam; learn how your comment data is processed.

You may use Markdown to format your comments; additionally, these HTML tags and attributes may be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

the Rick Beckman archive
Scroll to Top