I'm trying to remove old post tags from a few WP installs. In some instances, I have over 20k tags for a few thousand posts. I've tried the following code:
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy as tt
INNER JOIN wp_term_relationships as tr
WHERE tt.term_id = t.term_id
AND tr.term_taxonomy_id = tt.term_taxonomy_id
AND tt.taxonomy = 'post_tag'
AND tt.count < 5
This is supposed to delete any tags that are used on less than 5 posts. After I run it, I noticed that a number of categories are deleted as well (taxonomy = 'category') and I'm stumped why? Anyone else managed to do this??