Daily Tech Notes » WordPress

Starting from WordPress 2.6 (code named  Tyner), a new feature called post revisions is added in WordPress. This is a versioning system for WordPress posts and allows you to revert to an old version of a post if needed. You can also compare between versions to see the difference.

 

This is a good feature if you are using WordPress UI for writing your posts. But if you are using an external tool, you might not need this feature.

One of the problems with post revisions is that if you do a lot of editing, a lot of different versions are generated and are stored in the MySQL db. Over a period of time your database becomes bloated and performance of your blog can get affected. Unfortunately on the WordPress dashboard there is no option to disable post revisions.

So it is no wonder there are couple of plugins being released to add the post revision disabling option. But I am not a fan of plugins because many of the plugins come with security holes and many of them affects performance of the blog. So my mantra is to keep the number of plugins to a bare minimum.

Fortunately there is another way to disable post revisions in WordPress 2.6. You can edit wp-config.php and add the following line it,

define(’WP_POST_REVISIONS’, false);

This command sets a flag which instructs WordPress to avoid creating versioned copied of a post.  If you replace ‘false’ with a number, WordPress will ensure that the number of version generated for a post is limited by that number.

Another feature recently added to WordPress is the auto save feature. This saves your post every 60 seconds automatically when you are using the WordPress editor. If you don’t want this feature or you want a different interval, you can add the following entry in wp-config.php,

define( ‘AUTOSAVE_INTERVAL’, 60 );

The second parameter indicates the number of seconds after which the post is auto saved. You can set this to a large value to avoid frequent auto saves.

Where does WordPress store post revisions in DB?

You may be wondering where WordPress 2.6 stores post revisions in DB. If you are looking for a new table you are mistaken. All the post revisions are stored in the wp-posts table itself.  For the old revisions the post status is stored as ‘inherit’ and post_type as ‘revision’. The post_parent in this case is set as the id of the currently published post.

How do I delete old revisions of WordPress posts from MySQL DB?

You can use the following SQL script to delete all old revisions from MySQL DB. For large WordPress databases, this will improve performance of the blog.

delete from wp-posts where post_type=’revision’;

Scroll to Top