0

I know I can use define('WP_POST_REVISIONS', 5); to limit future post revisions to 5, but how would I go about purging all existing revisions except the latest 5?

3 Answers 3

0

Please take database backup and run a below MYSQL query and check is this helpful:

DELETE FROM wp_posts WHERE post_type = "revision" AND ID NOT IN(SELECT ID FROM wp_posts WHERE post_type = 'revision' ORDER BY ID DESC LIMIT 5)

2
  • Older versions of MySQL do not support using "limit" in subqueries. You might want to try this instead. SELECT * FROM wp_posts WHERE post_type = "revision" AND ID NOT IN(SELECT ID FROM (SELECT ID FROM wp_posts WHERE post_type = 'revision' ORDER BY ID DESC LIMIT 5) rev);
    – Tim
    Sep 11, 2020 at 14:00
  • You're correct - my version of mysql did not allow me to use the suggestion you're replying to. I ended up using your suggestion (and replacing the first SELECT with DELETE, although I think it ended up deleting them all because I don't see any revisions anymore. I did have a backup though.
    – Jonny
    Sep 11, 2020 at 17:14
0

To limit the number of revision saved in the future, you can use

define('WP_POST_REVISIONS', 5 );

Every time you'll save a post, a maximum number of 5 revisions will be kept in the database and all the older ones will be removed.

This will, however, remove them only when saving the posts, so you may want to manually use @Yash solution the first time if you really have a huge dataset.

0

I just found this plugin that lets you specify how many revisions you wish to keep:

https://wordpress.org/plugins/rvg-optimize-database/

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.