[wp-trac] [WordPress Trac] #30275: Exclude breaks wp_list_categories for non-hierarchical categories

WordPress Trac noreply at wordpress.org
Thu Nov 6 21:44:24 UTC 2014


#30275: Exclude breaks wp_list_categories for non-hierarchical categories
--------------------------+------------------
 Reporter:  thomask       |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  4.1
Component:  Taxonomy      |     Version:  4.0
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------
Changes (by boonebgorges):

 * milestone:  Awaiting Review => 4.1


Comment:

 Confirmed.

 The back story here is kinda complicated. In [8614],
 `wp_link_categories()` was modified so that the 'exclude' parameter always
 got translated into 'exclude_tree'. This makes sense when you use that
 function for categories (which are hierarchical). But when using it for
 non-hierarchical taxonomies, it has the side effect of short-circuiting
 some queries in `get_terms()`. In particular, `get_terms()` will run
 `get_terms( 'child_of' => $excluded_item )` for each member of
 `$exclude_tree`. But that secondary run of `get_terms()` automatically
 sets `child_of` to 0 for non-hierarchical taxonomies, under what I gather
 are the auspices of saving an unnecessary query. But in your case, it was
 causing the secondary call to `get_terms()` to return *all* terms in the
 taxonomy, with the result that *all* terms were being excluded from the
 query. Thus "no category found".

 Removing the lines in `get_terms()` that force 'child_of=0' for non-
 hierarchical taxonomies fixes the problem. What's more: it appears to
 actually *save* database queries in at least some cases, since a check for
 term children will return an empty array in these cases, avoiding later
 lookups. And since [29815], I think we have decent tests for child_of, and
 better understanding of it, so I feel comfortable taking it out.

 Thanks for the report.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30275#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list