Going through my database the other day, as part of a general site tidy-up, I was quite surprised to find I had 1700+ post revisions stored in the wp_posts table relating to 80-odd actual Posts and Pages.
That sure is lot of “junk”, all thanks to my rather unnecessary habit of frequently clicking the Save Draft button whilst writing a new Post, and each time you Save Draft a Post Revision is stored in the database. This is all well and good, as it is clearly a good idea to be able to roll back to an earlier draft if necessary. However, once the Post or Page is published, it’s fairly unlikely that these Post Revisions will be needed again. Also, is it really necessary to create a new Post Revision each time? Hands up those of you who have ever rolled back to a Post Revision previous to the most recent one? Thought so, not many of you!
This brief article shows you how to:
- Configure WordPress to limit the number of saved Post Revisions to a specific number
- Remove all Post Revisions from your database
Configure WordPress to limit the number of saved Post Revisions
Open up your wp-config.php file and add this code immediately above the “That’s all, stop editing! Happy blogging” line:
// Let's limit revisions to 3 define('WP_POST_REVISIONS', 3);
The number “3” tells WordPress to limit the number of Post Revisions to 3. Feel free to change this number to whatever you want (a positive integer only).
Don’t want any Post Revisions at all? Change the number to “0”, like this:
// Let's zap those revisions for good define('WP_POST_REVISIONS', 0);
Remove all Post Revisions from the database
Once you have reconfigured Post Revisions settings, as shown above, you might want to delete all the existing Post Revisions in your database so that you start with a clean slate.
Using phpMyAdmin, delete all Post Revisions in your wp_posts table using this SQL statement:
DELETE FROM wp_posts WHERE post_type = 'revision'
If you are using a custom table prefix (defined in your wp-config.php file), in the above SQL statement replace wp_posts with the actual table name.
Revision Management from the Codex.