Make WordPress Core

Changeset 18783


Ignore:
Timestamp:
09/26/2011 10:24:46 PM (13 years ago)
Author:
ryan
Message:

Count only published posts when updating term counts. Fire term count updates on transition_post_status. Props joehoyle. fixes #17548

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-filters.php

    r18705 r18783  
    255255add_action( 'save_post',                  '_save_post_hook',                          5, 2 );
    256256add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 );
     257add_action( 'transition_post_status',     '_update_term_count_on_transition_post_status', 10, 3 );
    257258add_action( 'comment_form',               'wp_comment_form_unfiltered_html_nonce'          );
    258259add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'                            );
  • trunk/wp-includes/post.php

    r18767 r18783  
    27282728    wp_transition_post_status('publish', $old_status, $post);
    27292729
    2730     // Update counts for the post's terms.
    2731     foreach ( (array) get_object_taxonomies('post') as $taxonomy ) {
    2732         $tt_ids = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'tt_ids'));
    2733         wp_update_term_count($tt_ids, $taxonomy);
    2734     }
    2735 
    27362730    do_action('edit_post', $post_id, $post);
    27372731    do_action('save_post', $post_id, $post);
     
    53125306add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
    53135307
     5308/**
     5309 * Update the custom taxonomies' term counts when a post's status is changed. For example, default posts term counts (for custom taxonomies) don't include private / draft posts.
     5310 *
     5311 * @access private
     5312 * @param string $new_status
     5313 * @param string $old_status
     5314 * @param object $post
     5315 * @since 3.3.0
     5316 */
     5317function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) {
     5318    // Update counts for the post's terms.
     5319    foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) {
     5320        $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) );
     5321        wp_update_term_count( $tt_ids, $taxonomy );
     5322    }
     5323}
    53145324?>
  • trunk/wp-includes/taxonomy.php

    r18661 r18783  
    24462446    } else {
    24472447        // Default count updater
    2448         foreach ( (array) $terms as $term) {
    2449             $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
    2450             do_action( 'edit_term_taxonomy', $term, $taxonomy );
    2451             $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
    2452             do_action( 'edited_term_taxonomy', $term, $taxonomy );
    2453         }
    2454 
     2448        _update_post_term_count( $terms, $taxonomy );
    24552449    }
    24562450
Note: See TracChangeset for help on using the changeset viewer.