When you edit a post or page in WordPress, a new version of the content is created. Since WordPress 3.6 has improved version visualization, as well as easier review and recovery. The WordPress revisions system stores a record of each saved draft or published update. The revision system allows you to see what changes were made in each revision
Different versions of a page or publication are stored in the database. With the accumulation of a large number of versions, the processing of the database queries becomes far from optimal.
Set maximum number of revisions to keep
It is good practice to support a small number of versions of publications and pages. You can set the maximum number of versions to keep. This is done in the wp-config.php configuration file by adding the following line:
define ('WP_POST_REVISIONS', 3); define('AUTOSAVE_INTERVAL', 300); // seconds
The number 3 shows the number of versions to keep. We’re also setting autosave interval to 5 minutes.
WP_POST_REVISIONS has the following attributes:
- true (default), -1: store every revision
- false, 0: do not store any revisions (except the one autosave per post)
- (int) > 0: store that many revisions (+1 autosave) per post. Old revisions are automatically deleted.
Delete existing revisions from database
After setting maximum number of revisions, it will be applied to all new versions. If there are already current versions, they will not be deleted. You can delete existing versions of publications and pages by executing an SQL query in the database. The query is as follows and can be executed in phpMyAdmin:
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'
In the example above, the table prefix is wp_ . If the prefix of your tables is different, you need to change it in the query.
Important: Before making changes to the database, back up the current content. In case of need, you will be able to recover the information immediately before the action is taken.
Disable WordPress Post Revisions
To completely disable WordPress post revisions add the following code in wp-config.php above the ‘ABSPATH’ otherwise it won’t work.
// Disable WordPress Post Revisions define('AUTOSAVE_INTERVAL', 300); // seconds define('WP_POST_REVISIONS', false);
Also we’ee adding a line to change the default autosave interval from 60 seconds (1 minute) to 300 seconds (5 minutes). Note, when you disable the post revisions there is still one autosave per post.