Posted By

jkriddle on 05/05/09


Tagged

wordpress tags unused


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

maxvee8
umang_nine
virendrakryadav


WordPress Query to Identify Unused Tags


 / Published in: MySQL
 

If you run a query to delete old posts manually from MySQL in a WordPress database, the old tags will remain and appear in your tag cloud/listing. This allows you to identify those unused tags, and then delete them with an additional query.

  1. SELECT * FROM wp_terms wt
  2. INNER JOIN wp_term_taxonomy wtt ON wt.term_id=wtt.term_id
  3. INNER JOIN wp_term_relationships wtr ON wtr.term_taxonomy_id=wtt.term_taxonomy_id
  4. LEFT JOIN wp_posts wp ON wp.ID=wtr.object_id
  5. WHERE
  6. taxonomy='post_tag'
  7. AND ID IS NULL
  8. AND NOT EXISTS(SELECT * FROM wp_terms wt2
  9. INNER JOIN wp_term_taxonomy wtt2 ON wt2.term_id=wtt2.term_id WHERE wtt2.parent=wt.term_id)
  10.  
  11. ORDER BY name

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: fncll on May 8, 2009

This is incredibly timely. Thanks!

Posted By: gfazioli on March 3, 2010

Doesn't work... :(

You need to login to post a comment.