This is a very old trick that was repeated over and over again but still very few people seems to acted on it.
If you are not using post revisions (and if you do not know what they are, chance is you are not) I wholeheartedly recommend that you disable them and also remove all traces of them from your database.
In recent optimization work we did, I found tens of thousands of post revision records which related to 150MB of database space used on one and 60MB on the other site. Not only it's making your database clunky and slow but you are paying a price for a feature most users simply do not use. When this happens on high traffic site you are probably paying double price.
Time for action!
First step, disable post revisions. Edit your wp-config.php (WordPress configuration file, found in the root of your WP installation) and add this line:
define('WP_POST_REVISIONS', false); |
Secondly we need to delete post revisions and associated data that is already in the database. So you will need access to your DB, either through command line 'mysql' or better with phpMyAdmin interface.
Select your database and execute this query:
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' |
This will remove all revision posts and associated objects from the database. I recommend running OPTIMIZE tables command after (in phpMyAdmin just mark all tables and select Optimize) to compact your database. And that's all folks.
Suggested reading:
- How to do a full WordPress backup and restore
- How to move WordPress site to new server with zero downtime
- How to toggle comments with one line of code
Posted in: WordPress
TAGS:can disable published wordpress, delete post revisions, disable revision comments wordpress, disabling deleting wordpress plugins, how disableposted bywordpress, post revisions, prelovac revisions, prelovac wordpress revisions, remove post revisions phpmyadmin, remove revisions wordpress, where post revisions, wordpress delete revisions, wordpress disable post delete, wordpress how remove revision, wordpress limit number revisions, wordpress post delete disable






14 Comments
awesome stuff -- 5 mins just sped my site up instantly.
Thanks for this, we turned of the post reviosns feature but then found that you can limit it also , so we set it to 5
http://www.youtube.com/watch?v=RkHi02VkZnk
After reading this post, I wanted to delete all of those post revisions, but honestly, I'm not a programmer although I can make due most of the time. I was grateful to see that there is a plugin that does this for you. Thanks to @Omar for sharing that. Ive already installed, activated, and run the plugin. Now, my database has been optimized and I've saved 5MB of space. Thanks guys!
nice trick mate uu help me to remove my WP-Optimize plugin :)
Thanks Vladimir - I do have client's that use the revisions feature to get back to a point before they messed their post up. What would be helpful is a function to only keep the last 10 revisions. Once a revision hits the number 11 spot, it is deleted. How would you do this? MAny thanks
Hi Nik,
To limit the number of revisions, do this:
define('WP_POST_REVISIONS', 3); // alter number of post revisions kept.
...and change the 3 to 10 for your example.
1-800-WPMODDER :)
Great stuff - thanks Adam. I subscribed to the feed on you site as well :)
@Vladimir - I was in customer service before web development. I would feel guilty knowing the quick answer and not sharing it, especially after all the knowledge and help I've received from fellow WordPress community members like yourself:)
@Nik - You're welcome, and thanks for subscribing!
Good stuff Adam. Does anyone have a query to remove extra term and meta records after all post revisions have already been removed ?
Nice tip, especially the database cleanup. I wrote something similar here with a couple extra lines you can add if you want to keep the post revisions but limit the time between saves and the number of revisions available.
define('AUTOSAVE_INTERVAL', 120 ); // seconds (default is 60)
define('WP_POST_REVISIONS', false ); // disable post revisions
define('WP_POST_REVISIONS', 3); // alter number of post revisions kept.
You make codings sound easy for some of the "dabblers" around here :) Good luck mr.Prelovac!
useful tips, thanks. You can also use the WP-Optimize plugin that enables both cleaning revisions and optimizing db tables. It also displays the status of each.
@Omer thanks for sharing great plugin, I currently using it on my site and adding it on my posts and pages revisions remover.