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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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)
Method 2
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.
Method 3
I just found this plugin that lets you specify how many revisions you wish to keep:
https://wordpress.org/plugins/rvg-optimize-database/
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0