8

In wp-config.php you're able to change how WordPress deals with post revisions. Specifically you're able to turn them off or specify a max number of revisions.

I'd like to be able to set a max number or revisions on a post type basis.

Is this possible?

3 Answers 3

1
  1. Remove the action 'wp_save_post_revision' from 'pre_post_update'. It is set per default in wp-includes/default-filters.php with the default priority (10).

  2. Add your own function to this hook. You get the $post_ID as parameter, so detecting the post type is easy.

  3. In your callback copy the code from wp_save_post_revision() but use the constant WP_POST_REVISIONS for the post type post only, and use different values for other post types. Not sure if it is possible to pass extra values in register_post_type()

1
  • 1
    This is the winner: gist.github.com/2884090 You do have to roll your own revision meta box, however. The built in one still uses WP_POST_REVISIONS. Jun 6, 2012 at 19:24
1

This is possible but it's not as simple as changing the WP_POST_REVISIONS property in the wp-config.php. This is possible by adding a filter to the 'wp_insert_post_data'.

Adding a filter is done like this:

add_filter('wp_insert_post_data' , 'my_insert_post_data');

function my_insert_post_data($data , $postarr) {
  // Check the revision stuff
  return $data;
}
2
  • 1
    Except wp_insert_post_data does not take care of deleting extra revisions, which is what I want to avoid. Jun 4, 2012 at 22:09
  • Upvoted. @ChristopherDavis Completely understand what you're after. On the other hand, this could be extended to maybe handle it...
    – kaiser
    Jun 4, 2012 at 23:01
0

after 11 years of the question, today I stumbled upon this question and here is my solution:

// keep 10 revisions for only posts.
// /wp-includes/revision.php:621
// filter: wp_{$post->post_type}_revisions_to_keep
add_filter('wp_post_revisions_to_keep', 'postRevisionsToKeep');
function postRevisionsToKeep(): int
{
    return 10;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.