Add comment_count to the posts table. Props donncha. fixes #1860

git-svn-id: https://develop.svn.wordpress.org/trunk@3104 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2005-11-16 06:29:36 +00:00
parent cae1b67170
commit 376a04e7de
6 changed files with 50 additions and 14 deletions
+10 -2
View File
@@ -30,7 +30,7 @@ function upgrade_all() {
upgrade_130();
}
if ( $wp_current_db_version < 3092 )
if ( $wp_current_db_version < 3104 )
upgrade_160();
save_mod_rewrite_rules();
@@ -300,7 +300,15 @@ function upgrade_160() {
$wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
}
}
// populate comment_count field of posts table
$comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments GROUP BY comment_post_ID" );
if( is_array( $comments ) ) {
foreach ($comments as $comment) {
$wpdb->query( "UPDATE $wpdb->posts SET comment_count = $comment->c WHERE ID = '$comment->comment_post_ID}'" );
}
}
// Some alpha versions used a post status of object instead of attachment and put
// the mime type in post_type instead of post_mime_type.
if ( $wp_current_db_version > 2541 && $wp_current_db_version <= 3091 ) {