Opened 2 years ago
Last modified 16 months ago
#56518 new defect (bug)
Terms with "0" slug do not work
Reported by: | serge.k | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.0.2 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
How to reproduce:
- Create tag with name "0" and slug "0"
- Assign it to a post
- 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)
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
@
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.
This sounds similar to #44872 but perhaps the code has changed since that fix.