WordPress.org

Make WordPress Core

Changeset 3091


Ignore:
Timestamp:
11/15/2005 04:31:24 PM (16 years ago)
Author:
ryan
Message:

Update category counts. Props donncha. fixes #1886

Location:
trunk
Files:
3 edited

Legend:

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

    r2966 r3091  
    3131    }
    3232   
    33     if ( $wp_current_db_version < 2966 )
     33    if ( $wp_current_db_version < 3091 )
    3434        upgrade_160();
    3535
     
    297297        $categories = $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories");
    298298        foreach ( $categories as $cat_id ) {
    299             $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->post2cat WHERE category_id = '$cat_id'");
     299            $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'");
    300300            $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
    301301        }
  • trunk/wp-includes/functions-post.php

    r3090 r3091  
    168168    if ($post_status == 'publish') {
    169169        do_action('publish_post', $post_ID);
     170
     171        // Update category counts.
     172        foreach ( $post_category as $cat_id ) {
     173            $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'");
     174            $wpdb->query("UPDATE $wpdb->categories SET category_count = '$count' WHERE cat_ID = '$cat_id'");
     175            wp_cache_delete($cat_id, 'category');       
     176        }
     177
    170178        if ($post_pingback && !defined('WP_IMPORTING'))
    171179            $result = $wpdb->query("
     
    478486    do_action('delete_post', $postid);
    479487
     488    if ( 'publish' == $post->post_status) {
     489        $categories = wp_get_post_cats('', $post->ID);
     490        if( is_array( $categories ) ) {
     491            foreach ( $categories as $cat_id ) {
     492                $wpdb->query("UPDATE $wpdb->categories SET category_count = category_count - 1 WHERE cat_ID = '$cat_id'");
     493                wp_cache_delete($cat_id, 'category');
     494            }
     495        }
     496    }
     497
    480498    if ( 'static' == $post->post_status )
    481499        $wpdb->query("UPDATE $wpdb->posts SET post_parent = $post->post_parent WHERE post_parent = $postid AND post_status = 'static'");
  • trunk/wp-includes/version.php

    r2966 r3091  
    44
    55$wp_version = '1.6-ALPHA-2-still-dont-use';
    6 $wp_db_version = 2966;
     6$wp_db_version = 3091;
    77
    88?>
Note: See TracChangeset for help on using the changeset viewer.