Limit the number of stored revisions per post in WordPress

It’s been a while since WordPress implemented revisions for posts and pages. Being able to revert a post or page to a previous state is a useful feature. However, I recently realized that WP creates a revision of the content every time it is saved, but there is no upper limit for the number of stored revisions. So, if you save your work quite often, it is very possible that the WordPress database is filled with numerous revisions of the content, which make the database grow in size quite aggressively. After thinking about it for a while, I realized that all those revisions are pretty useless to me. All I really care about is having a couple of recent revisions of each post or page available, so as to be able to get an idea of my recent changes.

It was only a matter of minutes to find out that it is possible to limit the number of stored revisions per post in WordPress. Open wp-config.php in your favorite editor and add the following:

/**
 * Revision management. Store 5 (+1 autosave) revisions per post.
 */
define('WP_POST_REVISIONS', 5);

The above setting forces WordPress to store only the 5 most recent revisions of the content. One extra revision is also saved because of the autosave feature.

The acceptable values for WP_POST_REVISIONS and their meanings are:

  • -1: store every revision (this is the default)
  • 0: do not store any revisions except for the one used for the autosave feature
  • N (integer) > 0: store N revisions per post. Revisions are rotated so that only the N most recent recent ones are available.

After getting rid of all those useless revisions that had piled up over the last months, I’m now quite happy with the size of the database. Although the idea of automatic revisions is fine, in my case, on-demand revisions would have been more useful and would make more sense in the way I author these posts.

Limit the number of stored revisions per post in WordPress by George Notaras, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2012 - Some Rights Reserved

About George Notaras

George Notaras is the editor of G-Loaded Journal, a technical blog about Free and Open-Source Software. George is a GNU/Linux enthusiast, a self-taught programmer and system administrator. He strongly believes that "knowledge is power" and has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora and spends some of his spare time developing open-source software. Follow George on Twitter: @gnotaras

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>