WordPress Term Taxonomy count is not in sync

This sql snippit updates the usage count of taxonomy terms.

UPDATE `wp_term_taxonomy`
JOIN (SELECT `term_taxonomy_id`,count(*) as `new_count`,`count` as `old_count`
FROM `wp_term_relationships`
JOIN `wp_term_taxonomy` USING (`term_taxonomy_id`)
GROUP BY `term_taxonomy_id`) as term_counts USING (`term_taxonomy_id`)
SET `count` = `new_count`
WHERE `old_count` != `new_count`

Leave a Reply

Your email address will not be published. Required fields are marked *