Skip to content

Instantly share code, notes, and snippets.

@bainternet
Created March 18, 2013 10:00
Show Gist options
  • Save bainternet/5186104 to your computer and use it in GitHub Desktop.
Save bainternet/5186104 to your computer and use it in GitHub Desktop.
delete all post revisions and all associated meta , comments, attachments and taxonomies
<?php
add_action('wp_footer','cleanup_revisions');
function cleanup_revisions(){
global $wpdb;
$sql = "SELECT `ID`
FROM ($wpdb->posts)
WHERE `post_type` = 'revision'
ORDER BY `ID` DESC";
$results = $wpdb -> get_results($sql,'ARRAY_N');
if($results){
echo "<!--";
$x = 0;
foreach ($results as $key => $value) {
wp_delete_post( $value['id']);
$x++;
}
echo "deleted $x post revisions -->";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment