Make WordPress Core

Ticket #29745: 29745.patch

File 29745.patch, 1.4 KB (added by jchristopher, 10 years ago)

Correct taxonomy term Count when filtering by post type

  • wp-admin/includes/class-wp-terms-list-table.php

     
    9999                if ( !empty( $_REQUEST['order'] ) )
    100100                        $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) );
    101101
     102                if ( !empty( $_REQUEST['post_type'] ) )
     103                        $args['post_type'] = trim( wp_unslash( $_REQUEST['post_type'] ) );
     104
    102105                $this->callback_args = $args;
    103106
    104107                $this->set_pagination_args( array(
     
    186189                        return;
    187190                }
    188191
     192                // update counts if limited to post type by tax_querying for an accurate post count
     193                if ( isset( $args['post_type'] ) && post_type_exists( $args['post_type'] ) ) {
     194                        foreach ( $terms as $term_key => $term ) {
     195                                $proper_term_count = new WP_Query( array(
     196                                                'post_type' => $args['post_type'],
     197                                                'nopaging' => true,
     198                                                'fields' => 'ids',
     199                                                'tax_query' => array(
     200                                                        array(
     201                                                                'taxonomy' => $taxonomy,
     202                                                                'field' => 'slug',
     203                                                                'terms' => $term->slug,
     204                                                        )
     205                                                )
     206                                        ) );
     207                                $terms[ $term_key ]->count = count( $proper_term_count->posts );
     208                        }
     209                }
     210
    189211                if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) {
    190212                        if ( ! empty( $args['search'] ) ) {// Ignore children on searches.
    191213                                $children = array();