Why WP_POST_REVISIONS Doesn’t Work (Sometimes)

I wanted to clamp the edits on one of my WordPress blogs recently, and decided to use the trusty old WP_POST_REVISIONS entry, where you add the following to wp-config.php:

define('WP_POST_REVISIONS', 3);

…Somewhere before the require_once function:

require_once(ABSPATH.'wp-settings.php');

Sounds good right?

It didn’t work.

A quick check on the forums assured me of two things:

  1. I wasn’t alone in having this issue.
  2. A lot of people were annoyed (VERY ANNOYED) by this failure.

Basically, if you use a number like 3 it clamps – SHOULD CLAMP – revisions to a maximum of the last 3 (plus any autosaves) – and if you use false like this:

define('WP_POST_REVISIONS', false);

No edits are saved.

Trying options, I hit on what I think is the problem – Revision Control.

Simply put, if you have an old post with revisions already, adding this entry doesn’t always make them disappear automatically from the database, or clean them up (although it might hide them from view – just remove the entry and they pop back again).

Here’s the kicker: Repeatedly saving copies so as to ‘trigger’ cleanup won’t work either, UNLESS YOU CHANGE THE TEXT. Revision control doesn’t see a new copy unless there are changes, so cleanup is not triggered. Change a letter or two, save it, and old entries are finally trashed.

So basically:

  1. Add the WP_POST_REVISIONS entry to your wp-config.php file.
  2. Go to any article you want trimmed.
  3. Change something in it and save.
  4. Change it back and save (unless you like the changes).

Of course, if you have lots of posts with revisions, heave a sigh, and leave them be – the effort to revise each and every one is simply not worth it. Frankly, I think WP should come with the entry already in wp-config.php, and set to something like 5 or 10 by default – better yet, a configurable setting in Admin to change it AND clean up the database would work well…

3 thoughts on “Why WP_POST_REVISIONS Doesn’t Work (Sometimes)

  1. I was suggested this blog by my cousin. I’m not sure whether this post is written by him as no one else know such detailed about my difficulty. You are wonderful! Thanks!

  2. I am trying to disable post revision following the code from tutorial but it’s giving me error in the code. Please rectify me.

    add_filter( `wp_revisions_to_keep`, `filter_function_name`, 10, 2 );

    function filter_function_name( $num, $post ) {

    return $num;

    }

  3. define(‘WP_POST_REVISIONS’, false);

    wont’t work, I don’t understand, how do you resolved (if you resolved)?