Make WordPress Core


Ignore:
Timestamp:
11/16/2005 06:29:36 AM (20 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/upgrade-functions.php

    r3092 r3104  
    3131    }
    3232   
    33     if ( $wp_current_db_version < 3092 )
     33    if ( $wp_current_db_version < 3104 )
    3434        upgrade_160();
    3535
     
    301301        }
    302302    }
    303    
     303
     304    // populate comment_count field of posts table
     305    $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments GROUP BY comment_post_ID" );
     306    if( is_array( $comments ) ) {
     307        foreach ($comments as $comment) {
     308            $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $comment->c WHERE ID = '$comment->comment_post_ID}'" );
     309        }
     310    }
     311
    304312    // Some alpha versions used a post status of object instead of attachment and put
    305313    // the mime type in post_type instead of post_mime_type.
Note: See TracChangeset for help on using the changeset viewer.