WordPress.org

Make WordPress Core

#25710 closed defect (bug) (fixed)

wp_list_categories 'exclude' not excluding categories

Reported by: mbijon Owned by: nacin
Milestone: 3.7.1 Priority: normal
Severity: normal Version: 3.7
Component: Template Keywords: has-patch commit fixed-major
Focuses: Cc:

Description

Category lists built with wp_list_categories('exclude=#') are not excluding the category|categories in the exclusion list.

This fails using either format of wp_list_categories():

wp_list_categories( array( 'exclude' => '#' ) );

wp_list_categories( 'exclude=#,##' );

I've tested several variations:

  • If you exclude a top-level, parent or child category it will still be listed
  • If you exclude a parent category but not the children, then the parent shows but the children do not
  • Other options like order, show_count, & depth don't appear to change this result

There are numerous reports of this bug in WP.org:

Attachments (1)

25710.diff (1.8 KB) - added by dd32 22 months ago.

Download all attachments as: .zip

Change History (12)

comment:1 @dd3222 months ago

  • Component changed from Themes to Template
  • Milestone changed from Awaiting Review to 3.7.1

Just trying to track this one down now.

comment:2 @dd3222 months ago

This was caused by [25162].

The behaviour of the exclude_tree get_terms() parameter changed, it now only excludes the children, not the actual parents, which is wrong.

Patch and unit tests incoming.

comment:3 @mbijon22 months ago

I was just thinking why don't we have tests for something this simple... Sounds like you'll beat me to it. Tks

comment:4 @mbijon22 months ago

Actually, @kovshenin already wrote a more-refined version of test_get_terms_include_exclude(). Although that may not catch this case, it's not in the SVN path I expected & I'm not sure which set of tests the core team has running for builds:

comment:5 @dd3222 months ago

The major problem is that there are no tests in that file which test hierarchical taxonomies, and as a result, none touch on the exclude_tree parameter.
There's a good reason for it, our hierarchical terms caches are a bit of a mess, you can't reliably create, and query a hierarchical term on the same request, even when using the cache cleaning API..

25710.diff is a basic unit test and patch that appears to fix this for me.

@dd3222 months ago

comment:6 @nacin22 months ago

In 25933:

Fix the exclude_tree argument in get_terms(), which fixes the exclude argument in wp_list_categories().

This was a 3.7 regression caused by [25162].

props dd32.
see #25710 for trunk.

comment:7 @nacin22 months ago

  • Keywords has-patch commit fixed-major added; needs-patch removed

comment:8 follow-up: @salromano22 months ago

So am I understanding this right? To patch this, I just need to change:

$excluded_children = array();

In wp-includes/taxonomy.php to:

$excluded_children = $exclude_tree;

?

Also, what of the other file, getTerms.php? Where do I find that?

comment:9 in reply to: ↑ 8 ; follow-up: @mbijon22 months ago

Replying to salromano:

So am I understanding this right? To patch this, I just need to change:

$excluded_children = array();

In wp-includes/taxonomy.php to:

$excluded_children = $exclude_tree;

That's correct. Just change the 1-line and your WP will work again.

The other file is a unit test that the core devs can run to check this isn't broken in the future. You don't need it at all to run WP.

comment:10 in reply to: ↑ 9 @salromano22 months ago

Replying to mbijon:

Replying to salromano:

So am I understanding this right? To patch this, I just need to change:

$excluded_children = array();

In wp-includes/taxonomy.php to:

$excluded_children = $exclude_tree;

That's correct. Just change the 1-line and your WP will work again.

The other file is a unit test that the core devs can run to check this isn't broken in the future. You don't need it at all to run WP.

Got it. Thanks, mate. Worked like a charm!

comment:11 @nacin22 months ago

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

In 25936:

Fix the exclude_tree argument in get_terms(), which fixes the exclude argument in wp_list_categories().

Merges [25933] to the 3.7 branch.

This was a 3.7 regression caused by [25162].

props dd32.
fixes #25710.

Note: See TracTickets for help on using tickets.