WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#14446 closed defect (bug) (fixed)

get_terms exclusions does not work w/ empty child_of taxonomies

Reported by: layotte Owned by:
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: has_patch
Focuses: Cc:

Description (last modified by nacin)

Just ran into this problem, I created a category heirarchy:

Departments
- ESSE
- KINS
- CSSE
- WELSF

But I did not want the category tree to show up in the category list. So I modified the wp_list_categories statement to be:

<?php wp_list_categories('title_li=&hide_empty=0&exclude=3878,3877'); ?>

3878 is the category ID of "Departments", it was excluding "Departments" without a problem, but was listing the children of Departments. At first I thought this might be a heirarchy vs. exlude_tree problem, then I realized that the problem was that these were newly created Categories and they were empty.

Currently during the exclusion process for $exclude_tree is to:

$excluded_children = (array) get_terms($taxonomies[0], array('child_of' => intval($extrunk), 'fields' => 'ids' ));

(line 925 of taxonomy.php)

This was returning an empty array because all the children were empty. My diff fixes this by adding 'hide_empty' => 0 to the get_terms command. If we're looking for children to exclude, we probably want to exclude the empty ones too :).

Diff attached.

Attachments (1)

taxonomy.diff (685 bytes) - added by layotte 4 years ago.

Download all attachments as: .zip

Change History (6)

layotte4 years ago

comment:1 nacin4 years ago

  • Description modified (diff)
  • Keywords changed from has_patch, needs_testing to has_patch needs_testing
  • Milestone changed from Awaiting Review to 3.1

comment:2 christian_gnoth4 years ago

  • Severity changed from normal to blocker

its not duplicate as I do not want exclude cats, but I want all child_of a cat - it is a similiar problem, but the get_terms function has to be changed on different places!!!

comment:3 christian_gnoth4 years ago

  • Severity changed from blocker to normal

comment:4 mdawaffe4 years ago

  • Keywords needs_testing removed

I'd like to see this in 3.0.2. #14663 depends on this ticket.

Patch tested.

comment:5 ryan4 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [15797]) Don't hide empty terms when determing exclude trees. Props layotte. fixes #14446

Note: See TracTickets for help on using tickets.