From f29d32da271656f622a41b34ae5030b1a1b8d057 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 12 Sep 2007 00:49:16 +0000 Subject: [PATCH] Resurrect count padding. git-svn-id: https://develop.svn.wordpress.org/trunk@6087 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/taxonomy.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index b8d1bff7a4..79e2e638d2 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -386,19 +386,22 @@ function &get_terms($taxonomies, $args = '') { $defaults = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => true, 'exclude' => '', 'include' => '', 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', - 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => ''); + 'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', + 'pad_counts' => false); $args = wp_parse_args( $args, $defaults ); $args['number'] = (int) $args['number']; if ( !$single_taxonomy || !is_taxonomy_hierarchical($taxonomies[0]) || '' != $args['parent'] ) { $args['child_of'] = 0; $args['hierarchical'] = false; + $args['pad_counts'] = false; } if ( 'all' == $args['get'] ) { $args['child_of'] = 0; $args['hide_empty'] = 0; $args['hierarchical'] = false; + $args['pad_counts'] = false; } extract($args, EXTR_SKIP); @@ -510,11 +513,9 @@ function &get_terms($taxonomies, $args = '') { $terms = & _get_term_children($child_of, $terms, $taxonomies[0]); } - /* - // Update category counts to include children. + // Update term counts to include children. if ( $pad_counts ) - _pad_category_counts($type, $categories); - */ + _pad_term_counts($terms, $taxonomies[0]); // Make sure we show empty categories that have children. if ( $hierarchical && $hide_empty ) { @@ -1129,6 +1130,24 @@ function &_get_term_children($term_id, $terms, $taxonomy) { return $term_list; } +// Recalculates term counts by including items from child terms +// Assumes all relevant children are already in the $terms argument +function _pad_term_counts(&$terms, $taxonomy) { + $term_hier = _get_term_hierarchy($taxonomy); + + if ( empty($term_hier) ) + return; + + foreach ( $terms as $key => $term ) { + if ( $children = _get_term_children($term->term_id, $terms, $taxonomy) ) { + foreach ( $children as $child ) { + $child = get_term($child, $taxonomy); + $terms[$key]->count += $child->count; + } + } + } +} + // // Default callbacks //