Skip to content

Instantly share code, notes, and snippets.

@malinky
Created February 12, 2015 10:06
Show Gist options
  • Save malinky/bff000432a1551085447 to your computer and use it in GitHub Desktop.
Save malinky/bff000432a1551085447 to your computer and use it in GitHub Desktop.
Wordpress DB Cleanup
/* Delete revisions */
DELETE FROM wp_posts WHERE post_type = "revision";
/**
* Also set in wp-config.php
* define( 'WP_POST_REVISIONS', 3 );
*/
/* Clean postmeta where the associated post no longer exists */
SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment