WordPress.org

Make WordPress Core

Changeset 6051


Ignore:
Timestamp:
09/06/07 22:56:03 (7 years ago)
Author:
ryan
Message:

Fix term count calculation during upgrade. fixes #4922

File:
1 edited

Legend:

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

    r6039 r6051  
    674674 
    675675    // Recalculate all counts 
    676     $terms = $wpdb->get_col("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy"); 
     676    $terms = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM $wpdb->term_taxonomy"); 
    677677    foreach ( (array) $terms as $term ) { 
    678         $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term'"); 
    679         $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term'"); 
     678        if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) ) 
     679            $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = '$term->term_taxonomy_id'"); 
     680        else 
     681            $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term->term_taxonomy_id'"); 
     682        $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term->term_taxonomy_id'"); 
    680683    } 
    681684} 
Note: See TracChangeset for help on using the changeset viewer.