Control How Many Revisions WordPress Stores in Database

Revisions in WordPress

Every time a post or page is created or updated, WordPress creates a revisions of that post or page. Chances are that you edit this post or page frequently. Imagine if these posts or pages are quite big you’l have a lot of redundant unused revisions in your database witch chunks up a lot of memory.

Limiting the amount of revisions stored by WordPress

Bigger database means losing performance over time and it’s also less manageable. That’s why you’ll have to take control over your revision amount stored by WordPress. You can configure WordPress how many number of revisions of your post/page it should keep in database.

How To control how many revisions WordPress stores in database

Add the following line of code to wp-config.php located at the root of your WordPress website. Best Practice is also include the comment. Chances are you’ll end up in the config.php file again then you can easily read the comment so you’ll know what this configuration does.

 * Define how many revisions wordpress should keep in database
define('WP_POST_REVISIONS', 3);

You can also configure WordPress to not store revisions. Here’s how:

 * Don't store any revisions to database
define('WP_POST_REVISIONS', false);

Does not remove Exiting revisions

Note that if you configure this option WordPress will not remove existing revisions from your database.

Manually remove existing revisions and metadata

You can however remove existing revisions by a database query. Always take a backup of your WordPress before you run queries directly to your database. Here is a query that wil remove all revisions from your database:

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 )
LEFT JOIN wp_term_taxonomy d ON ( b.term_taxonomy_id = d.term_taxonomy_id)
WHERE a.post_type = 'revision'
AND d.taxonomy != 'link_category';


You have to remember that when you set this revision size to zero you’ll have no revisions at all. This means that you’ll have no history of your previous changes, so be careful.


There are also plugins out there that’ll automatically clean up your WordPress database. But be cautious because they can also corrupt your database. For your information, I don’t use them myself. Here are a few of the most popular: WP-Optimize, WP Clean Up

You may also like...