WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#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 2 years ago.

Download all attachments as: .zip

Change History (12)

#1 @dd32
2 years ago

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

Just trying to track this one down now.

#2 @dd32
2 years 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.

#3 @mbijon
2 years ago

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

#4 @mbijon
2 years 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:

#5 @dd32
2 years 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.

@dd32
2 years ago

#6 @nacin
2 years 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.

#7 @nacin
2 years ago

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

#8 follow-up: @salromano
2 years 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?

#9 in reply to: ↑ 8 ; follow-up: @mbijon
2 years 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.

#10 in reply to: ↑ 9 @salromano
2 years 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!

#11 @nacin
2 years 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.