Make WordPress Core


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

Update category counts. Props donncha. fixes #1886

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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'");
Note: See TracChangeset for help on using the changeset viewer.