How to delete WordPress post revisions

Having revisions on my posts is nice I suppose. But I was starting to get a bit annoyed with the increasingly long list of revisions in each post. And they really did get long. Mainly because I am in a bit of a testing and experimenting phase which means that I have done a lost of adjustments to almost every single post so far because I don’t have 100% control on how I want things or how things will end up looking and so on :P

Anyways, I found a nice little MySQL snippet to clear out all of them in a French comment to a blog post. Thought I could share it here. Especially since I then know where to find it and it won’t disappear on me.

DELETE x,y,z
FROM wp_63nbis_posts x
LEFT JOIN wp_63nbis_term_relationships y ON (x.id = y.object_id)
LEFT JOIN wp_63nbis_postmeta z ON (x.id = z.post_id)
WHERE x.post_type = 'revision'

I did a select first (just swap delete x,y,z with select *) to check that it would delete what it was actually supposed to. And then a delete inside a transaction with another select afterwards, just in case :P (All of which are very easy to do in MySQL Query Browser)

By the way, in the comments to that mentioned blog post there are also mentioned some other solutions to this problem. For example:

  • Adding define('WP_POST_REVISIONS', N); to your wp-config.php file, where N would be the maximum number of revisions you want to allow, or -1 if you want them all.
  • Add a plugin to WordPress called revision delete!.

About Torleif

Was born in Hønefoss (Norway) the 20th of January 1985 around 16:05. I am a Seventh-Day Adventist, a software developer and a hobby juggler.
This entry was posted in Software Development and tagged , , . Bookmark the permalink.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>