Best way to delete post_tags and ONLY post_tags
-
What is the best SQL to use to DELETE post_tags AND only post_tags without deleting categories that may have the same name as the post_tag and therefore joined by a taxonomy record.
I found this SQL on this site sometime ago and used it but it seems to cause problems if a post_tag exists that also has a category of the same name. OR I have people complaining it does.
So if I only wanted to delete POST_TAGS where there were less than 4 articles using that tag I am currently using this SQL
DELETE a,c FROM wp_terms} AS a JOIN wp_term_taxonomy} AS c ON a.term_id = c.term_id WHERE ( c.taxonomy = 'post_tag' AND c.count <= 3 );
However if I switch the DELETE to a SELECT it only returns the post_tag records so looks ok to me.
Should I only delete from the wp_terms table e.g remove the ,c from the DELETE statement or is it okay to delete both records?
I thought the term_taxonomy record just joined the term up to the taxonomy so if I had a post_tag AND category using the same name e.g “Sales” there would be two term records and two term_taxonomy records.
As I said when I switch it to a SELECT it seems to return the correct data e.g
SELECT a.* , c.* from wp_terms as a JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id WHERE a.name='Sales' AND c.taxonomy = 'post_tag'
Just returns a record from both tables for the post tag NOT the category record.
I could add an extra LEFT JOIN in to return only records where the term doesn’t exist as another taxonomy type but can anyone see anything wrong with this or should I be leaving the term_taxonomy record alone and just deleting the from the terms table?
It’s just that I had someone complain about missing “records”, not very clear what they are saying to be honest but it seems after running this SQL they have some kind of mess.
Thanks for your help in advance.
- The topic ‘Best way to delete post_tags and ONLY post_tags’ is closed to new replies.