NOTE: Before making any changes to your database, we strongly recommend that you make a backup of your database.
It is therefore advisable to delete article revisions. However, to go further, we will ensure that the last X are kept to combine performance and security.
Clear all articles revisions
Run the SQL query below to delete all article versions. After this action, you will not be able to restore one of them to an earlier date.
DELETE a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_type = 'revision';
Clear revisions based on a date
To keep only the recent history of your articles, prefer this query. The last line indicates a date that you can change; in this case, January 1, 2010. Prior to this, all backups will be deleted.
Disable or reduce the number of versions per article
While historical usage is a good way to ensure that all changes on an article can be canceled quickly, this can be a waste of resources for your database.
To prevent versioning, you can add the following line to your wp_config.php file
Limit the number of versions per article
You can limit the number of versions per article by adding the following line to your wp_config.php file:
Revisions to articles are a major advantage of WordPress. It is not uncommon to have to go back after an unfortunate modification. Between SQL performance and level of risk, it’s up to you to find a happy medium.