Home > Blogging, Coding, Techie Stuff, WWW > Deleting Revision Posts from Wordpress Database

Deleting Revision Posts from Wordpress Database

January 26th, 2010 Leave a comment Go to comments

If you are using Wordpress to write your blog on your domain name, your wordpress database might be growing beyond your wildest imaginations!

Wordpress LogoWhen writing posts in the Wordpress Admin page, for reasons of security, Wordpress keeps autosaving your posts as you write them. It is a very handy feature especially if your internet is intent on sabotaging your hard work. For example, after thirty minutes of hard work, when you finally press the “Publish” button, your otherwise faithful browser might run into an error page thanks to that intermittent internet connection. Numerous thoughts flood your mind – “Is my work lost? Would pressing the back button recover my stuff? Would hitting refresh help? Do I have a backup!?.” Don’t worry, Wordpress’ autosave feature has it figured out for you.

But then, there is a catch. All these autosaves, multiple copies of them at that, get stored in your account’s database (remember, someone’s hosting your webpage?). They don’t even get deleted once you publish your post, and keep lurking around in your database even though you’ll probably never need them again. Now, if you are paying for your hosting, a few kilobytes lost here and there wouldn’t really affect you. Or if you don’t mind filthy databases, you wouldn’t care either. But if somehow, it aggravates you (like it does me), that despite having published only x posts, there are around 5x revision posts stuck in your database, I’m sure you would want to delete them.

And delete them, we shall!

I found this great SQL query online, and it works like a charm.

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’;

Don’t know what to do with this query? Just log into your webhosting site, go to phpMyAdmin (or equivalent) and then run this query on your Wordpress database. All your revision posts should get deleted and you’ll be a happy man. Disclaimer: It worked for me, it might not work for you. I last tested it on Wordpress 2.9.1 successfully.

Not finished yet? Want to get rid of these revisions forever!? Not a problem. You can add the following line to your wp-config.php file (already uploaded online).

define(‘WP_POST_REVISIONS’, false);

I personally don’t think it’s a good idea to turn off revisions. I’d rather just run that query above every now and then to get rid of the revision posts, but then hey, the quote “Each man to himself” wasn’t coined for nothing.

Categories: Blogging, Coding, Techie Stuff, WWW
  1. No comments yet.
  1. No trackbacks yet.