WordPress Revision Management Code Snippets

Revisions are a very helpful aspect of WordPress. However, over time your database can get clogged with hundreds of line items. Here’s a few handy code snippets to help manage WordPress revisions.

Add these to wp-config.php

Prevent WP from keeping revisions of your content:

define('WP_POST_REVISIONS', false)

Limit how many revisions WP keeps. Change the # to your preference:

define('WP_POST_REVISIONS', 3)

MySQL query to delete all post revisions. Use with caution!

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'