Opened 10 years ago
Closed 10 years ago
#25710 closed defect (bug) (fixed)
wp_list_categories 'exclude' not excluding categories
Reported by: |
|
Owned by: |
|
---|---|---|---|
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)
Change History (12)
#1
@
10 years ago
- Component changed from Themes to Template
- Milestone changed from Awaiting Review to 3.7.1
#2
@
10 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
@
10 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
@
10 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:
- Minimal test: http://core.trac.wordpress.org/browser/trunk/tests/tests/term/getTerms.php?rev=25162&order=name
- Kovshenin's refined test, that still passes this case: http://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/term/getTerms.php?rev=25257
#5
@
10 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.
#8
follow-up:
↓ 9
@
10 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:
↓ 10
@
10 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
@
10 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!
Just trying to track this one down now.