#30865 closed defect (bug) (wontfix)
$tax_query_defaults is hardcoded with "slug" as the field in the parse_tax_query function
Reported by: | jhned | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
There ought to be a check for if the term is numeric, because then the field would be the term_id, not the slug.
The built-in function wp_dropdown_categories clashes with this if you use it with a custom taxonomy. The default option values are term_ids, not slugs.
So, when submitting data from wp_dropdown_categories with a custom taxonomy, you get a tax_query that has a term_id for the term, but it's trying to match it against a slug, which results in a 404 page.
Ticket #30306 will certainly help mitigate this issue, but the root cause is that slug is being assumed without checking against the value of the term.
Attachments (1)
Change History (4)
#1
follow-up:
↓ 3
@
10 years ago
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
when submitting data from wp_dropdown_categories with a custom taxonomy, you get a tax_query that has a term_id for the term, but it's trying to match it against a slug, which results in a 404 page.
This sounds like a legitimate issue, but we can't solve it by doing is_numeric()
checks. Terms can have numeric slugs, so that a term with slug=45 would clash with a term with term_id=45. Currently, a my_custom_taxonomy=45
query var is interpreted as a slug; and changing it to be a term_id would break existing implementations. Moreover, even if we didn't have to worry about backward compatibility, doing this kind of invisible swapping-out of defaults is something that we should avoid doing except in cases where there's no possibility for ambiguity, because any bugs that arise from this sort of ambiguity are exceedingly hard to debug.
As you note, #30306 should solve the problem for the specific case of wp_dropdown_categories()
. For the broader issue of ambiguous custom taxonomy query vars, one possible solution is to add support for query vars of the format my_custom_taxonomy_field=slug
, which would be used to populate $tax_query_defaults
in parse_tax_query()
. But this seems like a lot of overhead to add if the only problem is with wp_dropdown_categories()
.
Marking as wontfix for the time being. If problems persist that aren't resolved by #30306, feel free to reopen with details.
Term Numeric Test