WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/wp revisions to keep

Description

The wp_revisions_to_keep filter allows developers to easily alter how many revisions are kept for a given post.

By default, an infinite number of revisions are stored if a post type supports revisions.

Usage

When the 'wp_revisions_to_keep' filter is called, it is passed two parameters: number of revisions to keep, and the WP_Post object of the current post.

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

function filter_function_name( $num, $post ) {
    return $num;
}

Where 'filter_function_name' is the function WordPress should call when filter is run. Note that the filter function must return a value after it is finished processing or the revisions will be empty.

filter_function_name should be unique function name. It cannot match any other function name already declared.

Examples

By post type

Sets the number of revisions for a theoretical post type 'my_custom_post'.

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

function filter_function_name( $num, $post ) {
    
    if( 'my_custom_post' == $post->post_type ) {
	$num = 5;
    }
    return $num;
}

Change Log

See Also