Make WordPress Core

Changeset 6087


Ignore:
Timestamp:
09/12/2007 12:49:16 AM (19 years ago)
Author:
ryan
Message:

Resurrect count padding.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r6050 r6087  
    387387                'hide_empty' => true, 'exclude' => '', 'include' => '',
    388388                'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
    389                 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '');
     389                'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '',
     390                'pad_counts' => false);
    390391        $args = wp_parse_args( $args, $defaults );
    391392        $args['number'] = (int) $args['number'];
     
    394395                $args['child_of'] = 0;
    395396                $args['hierarchical'] = false;
     397                $args['pad_counts'] = false;
    396398        }
    397399
     
    400402                $args['hide_empty'] = 0;
    401403                $args['hierarchical'] = false;
     404                $args['pad_counts'] = false;
    402405        }
    403406        extract($args, EXTR_SKIP);
     
    511514        }
    512515
    513         /*
    514         // Update category counts to include children.
     516        // Update term counts to include children.
    515517        if ( $pad_counts )
    516                 _pad_category_counts($type, $categories);
    517         */
     518                _pad_term_counts($terms, $taxonomies[0]);
    518519
    519520        // Make sure we show empty categories that have children.
     
    11301131}
    11311132
     1133// Recalculates term counts by including items from child terms
     1134// Assumes all relevant children are already in the $terms argument
     1135function _pad_term_counts(&$terms, $taxonomy) {
     1136        $term_hier = _get_term_hierarchy($taxonomy);
     1137
     1138        if ( empty($term_hier) )
     1139                return;
     1140
     1141        foreach ( $terms as $key => $term ) {
     1142                if ( $children = _get_term_children($term->term_id, $terms, $taxonomy) ) {
     1143                        foreach ( $children as $child ) {
     1144                                $child = get_term($child, $taxonomy);
     1145                                $terms[$key]->count += $child->count;
     1146                        }
     1147                }
     1148        }
     1149}
     1150
    11321151//
    11331152// Default callbacks
Note: See TracChangeset for help on using the changeset viewer.