Delete All Tags With 0 Posts

Delete all tags with zero posts tagged. Can also be used to delete all tags with one post. Or other amounts … Use at your own risk. From the MySQL command line. Make sure to BACK UP YOUR DATABASE first.

DELETE a,c FROM dbname.wp_terms AS a
LEFT JOIN dbname.wp_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN dbname.wp_term_relationships AS b on b.term_taxonomy_id = c.term_taxonomy_id
WHERE ( c.taxonomy = 'post_tag' AND c.count = 0 );

On the last line, you could also do c.count < 3 which would remove all tags with less than three posts. Be creative.

Enjoy!

Leave a Reply