Delete all unused taxonomy terms

Public

Deletes all taxonomy terms not associated to a node

Get raw version
php
  1. $results = db_query("
  2. SELECT t.tid FROM {taxonomy_term_data} t
  3. LEFT JOIN {taxonomy_index} i ON t.tid = i.tid
  4. WHERE i.tid IS NULL
  5. ");
  6. foreach ($results as $term) {
  7. taxonomy_term_delete($term->tid);
  8. }