Make WordPress Core

Ticket #17548: 17548.4.diff

File 17548.4.diff, 3.2 KB (added by joehoyle, 13 years ago)
  • wp-includes/default-filters.php

     
    255255add_action( 'publish_post',               '_publish_post_hook',                       5, 1 );
    256256add_action( 'save_post',                  '_save_post_hook',                          5, 2 );
    257257add_action( 'transition_post_status',     '_transition_post_status',                  5, 3 );
     258add_action( 'transition_post_status',     '_update_term_count_on_transition_post_status', 10, 3 );
    258259add_action( 'comment_form',               'wp_comment_form_unfiltered_html_nonce'          );
    259260add_action( 'wp_scheduled_delete',        'wp_scheduled_delete'                            );
    260261add_action( 'admin_init',                 'send_frame_options_header',               10, 0 );
  • wp-includes/taxonomy.php

     
    24462446        } else {
    24472447                // Default count updater
    24482448                foreach ( (array) $terms as $term) {
    2449                         $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term) );
     2449                        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON $wpdb->term_relationships.object_id = $wpdb->posts.ID WHERE $wpdb->term_relationships.term_taxonomy_id = %d AND $wpdb->posts.post_status != 'trash'", $term) );
    24502450                        do_action( 'edit_term_taxonomy', $term, $taxonomy );
    24512451                        $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) );
    24522452                        do_action( 'edited_term_taxonomy', $term, $taxonomy );
  • wp-includes/post.php

     
    27272727        $post->post_status = 'publish';
    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);
    27382732        do_action('wp_insert_post', $post_id, $post);
     
    52945288}
    52955289add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
    52965290
     5291/**
     5292 * 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.
     5293 *
     5294 * @access private
     5295 * @param string $new_status
     5296 * @param string $old_status
     5297 * @param object $post
     5298 * @since 3.3.0
     5299 */
     5300function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) {
     5301        // Update counts for the post's terms.
     5302        foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) {
     5303                $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) );
     5304                wp_update_term_count( $tt_ids, $taxonomy );
     5305        }
     5306}
    52975307?>