Search and Delete Unused Post Tags in WordPress

Print Page

Here are three SQL queries to find and safely delete all unused tags from your WordPress blog database.

The below command will show you all the unused tags in the database.

FROM wp_terms wterms INNER JOIN wp_term_taxonomy wttax ON wterms.term_id = wttax.term_id
WHERE wttax.taxonomy =  'post_tag' AND wttax.count =0;

Remember to change the ‘wp_’ prefix to the one in your installation.

Now that you know which are the unused tags, you can search and delete them from your dashboard or simply run the below commands to delete them all at once.

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