Search code examples
wordpresstagssql-delete

Mass delete unpopular Tags


Mass delete unpopular Tags

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!


Solution

  • $x = 5; // set this to any number
    $sql = "SELECT `name` FROM `wp_terms`";
    $result = mysql_query($sql);
    $count = array();
    while($row = mysql_fetch_assoc($result))
    {
      $count[$name]++;
    }
    foreach($count as $key = $value)
    {
      if($value < $x)
        {
          $sql2 = "DELETE FROM `wp_terms` WHERE `name` = '". $key ."'";
          $result2 = mysql_query($sql2);
        }
    }
    

    There's more efficient ways of doing it but this will do the job.

    Edit: make a backup first. I'm not entirely sure that that table is exclusive to tags.