To reset the tags of my posts in a particular category:
-- 1. Get term_taxonomy_id for category "tweets"
SELECT term_taxonomy_id
FROM wp_term_taxonomy tt
JOIN wp_terms t ON t.term_id = tt.term_id
WHERE t.name = 'tweets' AND tt.taxonomy = 'category';
-- suppose this returns term_taxonomy_id = X
-- 2. Remove all tag relationships for posts in that category
DELETE tr
FROM wp_term_relationships tr
JOIN wp_term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy = 'post_tag'
AND tr.object_id IN (
SELECT object_id FROM (
SELECT object_id FROM wp_term_relationships
WHERE term_taxonomy_id = 10
) AS temp
);
Leave a Comment