In my Wordpress blog I have 1000's of tags and I would like to simply delete all tags that aren't used more than X times... i.e. 5 times. Does anyone know of a simple way to do this? Even straight SQL would totally ROCK! Thanks a lot Mitch
Run this in your phpMyadmin or anywhere you can execute sql DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count <= 1 ); This will delete any tags that are not being used or used only once. You can change your count number to whatever you want. This will effectively remove them from everywhere the admin can see but they still exist in the relationship table DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy); Remember you need to change the 'wp_' to your prefix. Sorry no plugin, perhaps when I have time I will make one...
Josh, the guy who wrote that Wordpress forum post made a mistake. He forgot that taxonomy also includes post categories, link categories, and other terms. While it's unlikely that there will be other empty terms, it's best to only delete the tags. Also, the OP wanted to delete tags that weren't used more than five times. DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count<6 AND taxonomy='post_tag'); Code (markup):
You know, I didn't even notice that that was missing... I have used the same code before and added on the "taxonomy='post_tag'" but didn't think about adding it in the post. Thanks for catching that!
i used this code DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE count<=1 AND taxonomy='post_tag'); because i want to remove the tags which are used 1 times or less than 1 times. and some of rows deleted and i again run this code: DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy); i think related table need to be cleaned, so that we need this second. I am not perfect in mysql. Now I have very huge problem. I can't see my admin page. help me please.. i use 3.3.1 version of wordpress please really help me....