Too many wordpress tags?

If you had a plugin a few years ago like SEO SearchTerms Tagging 2 or others that added tags to posts when people searched for those terms.
You might find now that your theme has hundreds of tags that are not used or barely used, cluttering up your site.

So here’s a little SQL you can use to clean up those tags.


DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count = 0 );
DELETE FROM wp_term_taxonomy WHERE term_id not IN (SELECT term_id FROM wp_terms);
DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy);

This removes all tags with 0 posts. Change the wp_term_taxonomy WHERE count = 0 to wp_term_taxonomy WHERE count = 1 and you’ll remove all the tags used only once. change the 1 to a 2 and you’ll remove all the tags only used twice etc etc..