Archive for April, 2011

Deleting Post Revisions

Posted in SQL, Wordpress on April 10th, 2011 by jonolan

WordPress W/ Wrench - Tech and Tool Tips for WordPress.org sitesWhenever you create or edit an article in WordPress, the software suit will save multiple revision copies of the article. This is a waste of server and database resources. Excessive or extraneous revision records will increase the burden on the underlying database.

This will increase loop iterations, data retrieval, and page loading time.

Periodic deletion of these post revision and all their associated metadata should be considered part of your normal maintenance routine. This can be accomplished with a simple SQL statement:

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'

NOTE: Depending on exactly how WordPress was installed, the table names (wp_posts, wp_term_relationships, & wp_postmeta) may need to be modified to include the blog name, e.g., wp_yourblogposts.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon] [Twitter]