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

git-svn-id: http://svn.automattic.com/wordpress/trunk@3311 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-12-15 20:31:29 +00:00
parent d567007a42
commit fd28b6f640
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');