Created
March 18, 2013 10:00
-
-
Save bainternet/5186104 to your computer and use it in GitHub Desktop.
delete all post revisions and all associated meta , comments, attachments and taxonomies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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