Skip to content

Instantly share code, notes, and snippets.

@IlanVivanco
Last active March 16, 2021 13:26
Show Gist options
  • Save IlanVivanco/4f4a96488addaff4b0fe5b9f599fbe60 to your computer and use it in GitHub Desktop.
Save IlanVivanco/4f4a96488addaff4b0fe5b9f599fbe60 to your computer and use it in GitHub Desktop.
Update Post Count on Taxonomies
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')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment