Make WordPress Core

Opened 21 months ago

Last modified 9 months ago

#56518 new defect (bug)

Terms with "0" slug do not work

Reported by: sergek's profile serge.k Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.0.2
Component: Taxonomy Keywords:
Focuses: Cc:


How to reproduce:

  1. Create tag with name "0" and slug "0"
  2. Assign it to a post
  3. Open archive page for the tag, e.g.

You will get "not found" error. Same happens to another taxonomies as well, e.g. Post Categories.

That happens because array_filter() removes the "0" slug from $queryterms? in \WP_Tax_Query::transform_query() method.

Problem is here:

Change History (4)

#1 @joyously
21 months ago

This sounds similar to #44872 but perhaps the code has changed since that fix.

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

20 months ago

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

9 months ago

#4 @Cybr
9 months ago

Changing array_filter( $query['terms'] ); to array_filter( $query['terms'], 'strlen' ); would seem logical, but it may conflict when it's supposed to be term_taxonomy_id, where (int) 0 would be undesired.

This anonymous function as the filter callback would probably be better:
fn ( $term ) => is_string( $term ) ? strlen( $term ) : $term

I'm not sure if query parameter ?cat=42 will have 42 be an integer or string, but 0 wouldn't be accepted here anyway and causes the query to break in different ways due to $GLOBALS['wp']->public_query_vars being a hole.

Last edited 9 months ago by Cybr (previous) (diff)
Note: See TracTickets for help on using tickets.