How to disable, limit and delete WordPress post revisions?

how-to-disable-limit-delete-wordpress-post-revisions

If you are familiar with WordPress CMS, you might have observed that WordPress autsaves every edit by default. Post revisions is a good feature in WordPress to review and track changes. However, for some it may not be necessary as it is not required or due to database size concerns.

In this post, we shall see how to disable WordPress post revisions, set WordPress post revision to a certain number, deleted previous WordPress post revisions. 

So, I have a WordPress website too and I saw that the revision of a particular post is 229 already! I am not sure if there is a limit in WordPress up to how many latest revisions are saved. I guess there is none by default. It would be awesome if there is a setting for admins to set the revisions in WordPress.

wordpress-post-revisions-1


Anyway, I decided I do not need that many post revisions in my database. I also do not want to disable post revisions completely. You may want to completely disable revisions as per your need. Follow the steps below as per you need.

1) Disable WordPress post revisions
As discussed WordPress keeps post revisions by default. There is no UI to disable it. However, it can be defined in wp-config.php file.

Add the following line of code at the bottom of the wp-config.php file just above (require_once( ABSPATH . 'wp-settings.php' );) to disable WordPRess post revisions.

define('AUTOSAVE_INTERVAL', 300 ); // seconds
define('WP_POST_REVISIONS', false ); 

Place the code above the line: require_once( ABSPATH . 'wp-settings.php' ); 

This code will disable all future revisions to be saved and it will also increase the autosave interval from 60 seconds to 300 seconds. The post will be auto-saving every 5 minute instead of every minute.

2) Set WordPress post revision to a certain number
In my case, I did not disable the post revisions. I wanted to reduce the number of post revisions to keep.  To limit the number of WordPress post revisions, add the following line of code at the bottom of the wp-config.php file.

/** No. of revisions to keep */
define( 'WP_POST_REVISIONS', 2 );
Place the code above the line: require_once( ABSPATH . 'wp-settings.php' );

This will keep only two post revisions in the database.

3) Delete previous WordPress post revisions

As discussed above, we can disable and limit the post revisions. However, doing the above changes does not remove the previous post revisions already saved in the database, which are occupying unnecessary space.

To delete the previous post revisions from WordPress database, do the following:
  • Login to your host Control Panel
  • Launch phpMyAdmin
See the post revisions in WordPress database:

Launch phpMyAdmin > Click on SQL tab and run the query:

SELECT ID,post_title,post_type FROM `wp_posts` where post_type="revision";

Note: If table prefix (wp) has been changed, use appropriate table prefix in your case.

This query will show you all the posts which are of type - post revisions.

wordpress-post-revisions-phymyadmin





Find out how many post revisions are there in the WordPress database:

Launch phpMyAdmin > Click on SQL tab and run the query:

SELECT count(*) FROM `wp_posts` where post_type="revision";

Note: If table prefix (wp) has been changed, use appropriate table prefix in your case.

This query will display the number of post revisions in the database.

Delete the post revisions from database:

To delete the post revisions, run the following query from phpMyAdmin:

DELETE FROM wp_posts WHERE post_type = "revision";

Note: If table prefix (wp) has been changed, use appropriate table prefix in your case.

The steps in this post should disable Post revisions, set a limit to the number of post revisions to keep and delete all previously saved post revisions stored in the WordPress database.

Post revisions may be a useful feature but if it is not necessary for you, you may following the steps above to disable or limit the post revisions as discussed.


No comments