# Revision Limits per Post Type

> Keeps a different number of revisions for each content type, for example many for posts and none for products.

- Type: PHP
- Runs: Run everywhere
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: performance, revisions, database
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/revisions-per-post-type/

## Code

```php
// Post type => revisions to keep (0 = none, -1 = unlimited). Other types keep the site default.
$wpide_revisions_by_type = array(
    'post'    => 10,
    'page'    => 5,
    'product' => 0,
);

add_filter( 'wp_revisions_to_keep', function ( $num, $post ) use ( $wpide_revisions_by_type ) {
    return isset( $wpide_revisions_by_type[ $post->post_type ] ) ? (int) $wpide_revisions_by_type[ $post->post_type ] : $num;
}, 10, 2 );
```

## Notes

Older revisions beyond the limit are removed the next time the item is saved.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Revision Limits per Post Type" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
