Skip to content

Instantly share code, notes, and snippets.

@mafsdisseny
Created September 17, 2015 09:35
Show Gist options
  • Save mafsdisseny/a6a8ffb1e730d111615f to your computer and use it in GitHub Desktop.
Save mafsdisseny/a6a8ffb1e730d111615f to your computer and use it in GitHub Desktop.
Wordpress, Update the count parameter for a taxonomy, after data migration. In this case, only specify the post type name, and the associated taxonomies will be updated.
UPDATE wp_term_taxonomy tt
SET count =
(SELECT count(p.ID) FROM wp_term_relationships tr
LEFT JOIN wp_posts p
ON (p.ID = tr.object_id AND p.post_type = 'post_type_name' AND p.post_status = 'publish')
WHERE tr.term_taxonomy_id = tt.term_taxonomy_id
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment