Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update WordPress taxonomies(categories/tags)' count field after bulk import/delete

Tags:

wordpress

How to update WordPress taxonomies(categories/tags)' count field after bulk import/delete?

Related questions:

WordPress › Support » Fix comment and category counts after import http://wordpress.org/support/topic/fix-comment-and-category-counts-after-import

like image 329
kaorukobo Avatar asked Sep 07 '13 03:09

kaorukobo


1 Answers

This SQL helps:

UPDATE wp_term_taxonomy SET count = (
SELECT COUNT(*) FROM wp_term_relationships rel 
    LEFT JOIN wp_posts po ON (po.ID = rel.object_id) 
    WHERE 
        rel.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id 
        AND 
        wp_term_taxonomy.taxonomy NOT IN ('link_category')
        AND 
        po.post_status IN ('publish', 'future')
)
like image 125
kaorukobo Avatar answered Sep 20 '22 18:09

kaorukobo