From a313da93d7c2b2182278a70bbb22ecec2a75a968 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 17 Aug 2006 04:46:16 +0000 Subject: [PATCH] Update category counts to include children. Don't hide empty parent cats that have non-empty children. Props skeltoac. git-svn-id: https://develop.svn.wordpress.org/trunk@4104 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/category.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/wp-includes/category.php b/wp-includes/category.php index 31274822d9..648ef4f0fa 100644 --- a/wp-includes/category.php +++ b/wp-includes/category.php @@ -67,7 +67,7 @@ function &get_categories($args = '') { $exclusions = apply_filters('list_cats_exclusions', $exclusions, $r ); $where .= $exclusions; - if ( $hide_empty ) { + if ( $hide_empty && !$hierarchical ) { if ( 'link' == $type ) $where .= ' AND link_count > 0'; else @@ -103,6 +103,22 @@ function &get_categories($args = '') { if ( $child_of || $hierarchical ) $categories = & _get_cat_children($child_of, $categories); + // Update category counts to include children. + if ( $hierarchical ) { + foreach ( $categories as $k => $category ) { + $progeny = $category->category_count; + if ( $children = _get_cat_children($category->cat_ID, $categories) ) { + foreach ( $children as $child ) + $progeny += $child->category_count; + } + if ( !$progeny && $hide_empty ) + unset($categories[$k]); + else + $categories[$k]->category_count = $progeny; + } + } + reset ( $categories ); + return apply_filters('get_categories', $categories, $r); }