Skip to content

Instantly share code, notes, and snippets.

@beezee
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beezee/11255442 to your computer and use it in GitHub Desktop.
Save beezee/11255442 to your computer and use it in GitHub Desktop.
Synchronize wp_term_taxonomy post counts in one query
update wp_term_taxonomy as tt
left join (select term_taxonomy_id as tid, count(term_taxonomy_id) as real_count
from wp_term_relationships as tr
left join wp_posts as p on tr.object_id = p.ID
where p.post_status = "publish"
group by tid)
as rc
on rc.tid = tt.term_taxonomy_id
set tt.count = rc.real_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment