From fd28b6f6407cd880968e742a5b8c600c3e182c51 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 15 Dec 2005 20:31:29 +0000 Subject: [PATCH] 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 --- wp-includes/functions-post.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index 38c7540931..76460fc86d 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -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');