Limit the number of WordPress revisions

by James McDonald | Jun 9, 2026 | IT Tips | 0 comments

Make wordpress keep a smaller number of revisions

# wp-config.php

# limit post revisions
define('WP_POST_REVISIONS', 5);

# put the setting before this comment
/* That's all, stop editing! Happy blogging. */

Remove extra revisions

DELETE r FROM wp_posts r
INNER JOIN (
    SELECT ID
    FROM (
        SELECT ID,
               ROW_NUMBER() OVER (PARTITION BY post_parent ORDER BY post_date DESC) AS row_num
        FROM wp_posts
        WHERE post_type = 'revision'
    ) ranked
    WHERE row_num > 5
) AS old_revisions
ON r.ID = old_revisions.ID;

0 Comments

Submit a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.