[wp-trac] [WordPress Trac] #16863: get_terms hierarchical/hide_empty incompatible with include/exclude args
WordPress Trac
wp-trac at lists.automattic.com
Wed Mar 16 12:37:06 UTC 2011
#16863: get_terms hierarchical/hide_empty incompatible with include/exclude args
----------------------------+-----------------------------
Reporter: martinshopland | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 3.1
Severity: normal | Keywords: has-patch
----------------------------+-----------------------------
{{{
$terms = get_terms('taxName', array(
'hierarchical' => true,
'hide_empty' => true,
'include' => array(1, 2, 3)
));
}}}
$terms will not contain a meaningful result set. In order for get_terms to
process 'hierarchical' correctly it must recieve in 'include' a full list
of term ids for all child terms that may have count > 0, this obviously
negates the point of 'include' here.
'include/exclude' is processed at query level, 'hierarchical' is processed
post query and expects the results of the query to be unfiltered.
The following patch seems to fix the issue in my application, I think this
approach would need to take in 'child_of' also, which I haven't done here.
{{{
diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php
index 89532dc..2f51bea 100644
--- a/wp-includes/taxonomy.php
+++ b/wp-includes/taxonomy.php
@@ -1337,9 +1337,13 @@ function &get_terms($taxonomies, $args = '') {
// Make sure we show empty categories that have children.
if ( $hierarchical && $hide_empty && is_array($terms) ) {
+
+ $taxTerms = !(empty($include) && empty($exclude) &&
empty($exclude_tree)) ?
+ get_terms($taxonomies) : $terms;
+
foreach ( $terms as $k => $term ) {
if ( ! $term->count ) {
- $children =
_get_term_children($term->term_id, $terms, $taxonomies[0]);
+ $children =
_get_term_children($term->term_id, $taxTerms, $taxonomies[0]);
if ( is_array($children) )
foreach ( $children as $child )
if ( $child->count )
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16863>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list