Opened 9 years ago
Last modified 9 years ago
#43445 new defect (bug)
Wildcard `LIKE` support for `WP_Meta_Query` (and maybe other queries?)
| Reported by: | boonebgorges | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
Passing LIKE as the compare parameter for a meta query (or compare_key, after [42768]) results in what is essentially a "contains" query for the literal value (or key) string. So:
array(
'compare' => 'LIKE',
'value' => 'foo',
)
becomes WHERE ... value LIKE '%foo%'.
MySQL LIKE wildcard characters % and _ are escaped, so it's not possible to do a non-standard anchored search, or any other custom LIKE query.
It would be nice if you could pass a string like foo% and have the wildcard characters respected.
A few considerations:
- Syntax. A potential solution is suggested in https://core.trac.wordpress.org/ticket/42409#comment:14. Another possibility is a filter for enabling the "non-escaped" version
- Security. I'm unsure that there's a way to do this without introducing security issues, specifically around the
%character. Any potential patch would need serious review.
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Closely related: #23373