How to Delete WordPress Post Revisions

by Simon. Average Reading Time: less than a minute.

WordPress has a nice little feature of saving revisions of your posts whilst you’re editing them. This is great if you need to roll back to a previous revision. However, after you’ve published a post, it’s unlikely you’ll need the old revisions.

The following SQL can be used to delete the old post revisions and free up some space for your database.

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'

Of course, it’s a good idea to back up your database prior to deleting anything.

If you don’t want or need post revisions, you can add this line to your config.php to turn them off completely.

define('WP_POST_REVISIONS', false);

This article has been tagged

, , , ,

Other articles I recommend

How to Fix a SQL Injection Attack

In my previous post, What is a SQL Injection Attack, I gave a brief overview of SQL injection and Cross-Site Scripting (XSS), primarily with regard to websites. In the example given, we saw that an attack could take the form of a ‘hacked’ URL which contained either a literal SQL statement, or a hexadecimal string that could be interpreted by an insecure SQL database server.

ColdFusion ORM Frameworks & Tools

Object-Relational Mapping (or ORM), is a programming technique that links databases to object-oriented language concepts, creating (in effect) a “virtual object database”. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to code their own object-relational mapping for their systems.

Secure Your WordPress Installation

Security is often an overlooked aspect of blogging, but a few minutes making sure things are secure can save you hours and hours of ‘fixing’ if someone decides to mess with your site.