Skip to content

Instantly share code, notes, and snippets.

@steamboatid
Created November 19, 2022 04:32
Show Gist options
  • Save steamboatid/166c658f05d06fd95b0bfba741805e56 to your computer and use it in GitHub Desktop.
Save steamboatid/166c658f05d06fd95b0bfba741805e56 to your computer and use it in GitHub Desktop.
delete all wordpress terms
DELETE a, b, c
FROM `wp_term_relationships` AS a
INNER JOIN `wp_term_taxonomy` AS b ON (a.`term_taxonomy_id` = b.`term_taxonomy_id`)
INNER JOIN `wp_terms` AS c ON (b.`term_id` = c.`term_id`)
WHERE a.`object_id` IN (SELECT `ID` FROM `wp_posts` WHERE `post_type`='post');
DELETE a, b, c
FROM `wp_term_relationships` AS a
INNER JOIN `wp_term_taxonomy` AS b ON (a.`term_taxonomy_id` = b.`term_taxonomy_id`)
INNER JOIN `wp_terms` AS c ON (b.`term_id` = c.`term_id`)
WHERE a.`object_id` NOT IN (SELECT `ID` FROM `wp_posts`);
DELETE
FROM `wp_terms`
WHERE `term_id` IN
(SELECT `term_id` FROM `wp_term_taxonomy` WHERE `count` = 0);
DELETE
FROM `wp_terms`
WHERE `term_id` NOT IN
(SELECT `term_id` FROM `wp_term_taxonomy`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment