Mass delete unpopular Tags

Discussion in 'WordPress' started by mm-93, Dec 27, 2010.

  1. #1
    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
     
    mm-93, Dec 27, 2010 IP
  2. Josh Fowler

    Josh Fowler Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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 Fowler, Dec 29, 2010 IP
  3. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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):
     
    Cash Nebula, Dec 29, 2010 IP
  4. Josh Fowler

    Josh Fowler Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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!
     
    Josh Fowler, Dec 30, 2010 IP
  5. hackawere

    hackawere Member

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #5
    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....
     
    hackawere, Feb 20, 2012 IP