Skip to content

Instantly share code, notes, and snippets.

@fulippo
Created October 31, 2012 10:26
Show Gist options
  • Save fulippo/3986307 to your computer and use it in GitHub Desktop.
Save fulippo/3986307 to your computer and use it in GitHub Desktop.
Query to remove orphaned taxonomy terms from a WordPress DB
-- Replace %s with table prefix
DELETE tr
FROM %s_term_relationships tr
INNER JOIN %s_term_taxonomy tt
ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.taxonomy != 'link_category'
AND tr.object_id NOT IN (SELECT ID FROM %s_posts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment