Last active
August 29, 2015 14:00
-
-
Save beezee/11255442 to your computer and use it in GitHub Desktop.
Synchronize wp_term_taxonomy post counts in one query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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