When changing a post's categories, redo category counts for both old and new cats. Props ringmaster. fixes #2085

git-svn-id: https://develop.svn.wordpress.org/trunk@3311 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2005-12-15 20:31:29 +00:00
parent 44fc04c42e
commit 7321cfa5a1
1 changed files with 2 additions and 1 deletions

View File

@ -504,7 +504,8 @@ function wp_set_post_cats($blogid = '1', $post_ID = 0, $post_categories = array(
}
// Update category counts.
foreach ( $post_categories as $cat_id ) {
$all_affected_cats = array_unique(array_merge($post_categories, $old_categories));
foreach ( $all_affected_cats as $cat_id ) {
$count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat, $wpdb->posts WHERE $wpdb->posts.ID=$wpdb->post2cat.post_id AND post_status='publish' AND category_id = '$cat_id'");
$wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
wp_cache_delete($cat_id, 'category');