WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#35156 closed defect (bug) (fixed)

wp_list_categories() does not accept comma-separated IDs for exclude_tree parameter

Reported by: gblsm Owned by: boonebgorges
Milestone: 4.4.1 Priority: normal
Severity: normal Version: 4.4
Component: Taxonomy Keywords: fixed-major
Focuses: Cc:
PR Number:

Description

This does not work:

wp_list_categories( array( 'exclude_tree' => '9,10' ) );

as only the category ID=9 and its descendants will be excluded, while ID=10 will be included.
But this works:

wp_list_categories( array( 'exclude_tree' => array( 9, 10 ) ) );

as the categories ID=9, 10 and their descendants will be excluded.

Attachments (2)

category-template.php.diff (717 bytes) - added by gblsm 4 years ago.
35156-test.patch (4.4 KB) - added by hnle 4 years ago.

Download all attachments as: .zip

Change History (15)

#1 @hnle
4 years ago

Related: #12981

#2 in reply to: ↑ description @tg29359
4 years ago

The reference page of wp_list_categories() says that,

'exclude_tree'
(array|string) Array or comma/space-separated string of term IDs to exclude, along with their descendants. See get_terms().

https://developer.wordpress.org/reference/functions/wp_list_categories/

I also think the behavior reported with this ticket does not match the description of the reference.

#3 @gblsm
4 years ago

Applying wp_parse_id_list() instead of the cast “(array)” seems fixing the bug. The patch does it.

#4 @gblsm
4 years ago

Related: [34696]

#5 follow-up: @boonebgorges
4 years ago

  • Keywords has-patch added

Thanks for the patch, @gblsm. Did you notice this issue because it worked in 4.3 but not in 4.4? It looks like it might be a regression.

#6 in reply to: ↑ 5 @gblsm
4 years ago

Replying to boonebgorges:

This issue was reported at https://ja.forums.wordpress.org/topic/157359 by @odmodm then @tg29359 encouraged opening a ticket.

@hnle
4 years ago

#7 @hnle
4 years ago

  • Keywords has-unit-tests added

#8 @boonebgorges
4 years ago

  • Milestone changed from Awaiting Review to 4.4.1
  • Owner set to boonebgorges
  • Status changed from new to assigned

Thanks for the patches, @gblsm and @hnle. It does look like this is a 4.4 regression, so let's fix for 4.4.1.

#9 @boonebgorges
4 years ago

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

In 36005:

Ensure that wp_list_categories() supports comma-separated lists for 'exclude' and 'exclude_tree'.

[34696] introduced a regression whereby comma-separated values for 'exclude'
and 'exclude_tree' would be handled improperly when merging the two parameters,
resulting in category IDs being incorrectly dropped from the combined array.

Props gblsm, hnle.
Fixes #35156.

#10 @boonebgorges
4 years ago

  • Keywords fixed-major added; has-patch has-unit-tests removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 4.4.1.

#11 follow-up: @boonebgorges
4 years ago

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

In 36006:

Ensure that wp_list_categories() supports comma-separated lists for 'exclude' and 'exclude_tree'.

[34696] introduced a regression whereby comma-separated values for 'exclude'
and 'exclude_tree' would be handled improperly when merging the two parameters,
resulting in category IDs being incorrectly dropped from the combined array.

Merges [36005] to the 4.4 branch.

Props gblsm, hnle.
Fixes #35156.

#12 in reply to: ↑ 11 @gblsm
4 years ago

Thanks @boonebgorges, I see the version 4.4.1-alpha-36006 has the code fixed!

This ticket was mentioned in Slack in #core by boone. View the logs.


4 years ago

Note: See TracTickets for help on using tickets.