WP: Revs

2010-03-21 by | Cats: Code · Hacks · HV · WordPress | Tags: ,

Managing WordPress Post Revisions

WP post “revisions” have saved my ass more than once. Intro-ed in WP 2.6, they let you save, view, and restore past versions of your posts.

But when it comes to database backup, all those revisions can be too much of a good thing. E.g., all my wp tables together weigh in at 18MB right now. Without the revisions, those same tables total 3MB (rev inflation factor of 6).

So, before db backups, I usually delete the revisions (which are a post-type) along w/ those revs’ post meta and terms. To do this, run this sql query (e.g., via phpMyadmin):

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'

By default WP saves every single rev of a post, which can be bunches. To set the max number of revs stored to some more sane number, add this to your wp-config.php file:

/* Save only last 10 post revisions */
define( 'WP_POST_REVISIONS', 10 );

Sick of the whole rev-save thang? Turn it off with:

define( 'WP_POST_REVISIONS', false );

“Rev-Up” The Revillos (2:21 mp3):

Play audio:

Ref: Andrei Neculau | Lester Chan | OptiNiche

Database Diet

While your sql-ing, consider these other db reducers…

Remove custom-field clutter left by, for instance, deactivated plugins:

DELETE FROM wp_postmeta WHERE meta_key = 'your-meta-key';

Get rid of not-yet-deleted spam:

DELETE FROM wp_comments WHERE comment_approved = 'spam';

Ref: WP support | OXP | CatsWhoCode.

Bookmark and Share

Comments are closed.