How to Delete WordPress Revisions (Correctly)

There is an easy way to delete wordpress revisions but is it the correct way? This article explores the wordpress revision feature.

WordPress Revisions

MySQL is the typical database that most servers running wordpress use. Mysql can handle 20 million records without too much of an issue. More important than the number of records are how they are indexed and used. A poorly designed database can be slow after only 1000 records.

How does this apply to wordpress revisions? Well, it doesn’t! However, you may not want 15 revisions of an article junking up your database because of space, or other reasons. The larger the database:

  • Large databases cost more to backup
  • Large databases take more time to backup/move/repair/maintain, etc
  • Large databases are harder to muck around in
  • There are more chances of disk i/o error in large databases

Dangers of Deleting WordPress Revisions (incorrectly)

  • Delete incorrect link using the common “join” delete
  • Taxonomies can be broken if wordpress revisions are deleted incorrectly
  • Wrong data can be deleted when you delete wordpress revisions

For the most part, unless you break a taxonomy or other link during your deletes, there is no problem. The bad news is the following code, which is posted on hundreds of sites, breaks taxonomies and is not recommended:

So, don’t use the code above! Instead we recommend the methods that follow to delete wordpress revisions.

Correct Way to Delete WordPress Revisions

Here are 2 ways to correctly delete wordpress revisions:

Plugins
Some plugins simply have the code above, which is wrong. The RVG Optimize DB plugin correctly addresses how to delete revisions though.
WP CLI
https://wp-cli.org/commands/post/delete/ tells how do do it via the WP CLI method. A sample of how this might work is:

Preventing WordPress Revisions

Regardless of the method that you choose, you should limit future wordpress revisions based on your site specifics.

Open your wp-config.php file and add one of the following versions:

If you want to limit to a certain number (draft is always there, this is in addition to draft):

or if you want to completely disable wordpress revisions in the future:

or if you want to keep unlimited revisions, but want to not have so many:

Just modify your wp-config.php to match how you want your site database to operate and then save the file.

Want WordPress Administration Help?

We can help you solve all types of WordPress problems. Please contact us for WordPress Consulting.

Leave a Reply

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