Make WordPress Core

Opened 2 years ago

Last modified 16 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:

Description

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. https://example.com/tag/0/

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:
https://github.com/WordPress/WordPress/blob/6b1cabaea14273b59645714cb3aa4be00e6c9dbb/wp-includes/class-wp-tax-query.php#L609

Change History (4)

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


2 years ago

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


16 months ago

#4 @Cybr
16 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 16 months ago by Cybr (previous) (diff)
Note: See TracTickets for help on using tickets.