Opened 20 months ago
Last modified 5 months ago
#18707 new enhancement
Meta Query printing "array" in query whwn compara type is LIKE
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Query | Version: | 3.2.1 |
| Severity: | normal | Keywords: | has-patch 2nd-opinion |
| Cc: | r@… |
Description
Always a try to filter post by meta_query using a array value and compare equals to "LIKE" the returned SQL query is buged. WordPress return something like this:
(wp_postmeta.meta_key = 'passed_key_value' AND CAST(wp_postmeta.meta_value AS CHAR) LIKE '%Array%'))
The array values are not serialized, and "Array" are outputed to in SQL Query.
Serializing the values the problem still the same and WordPress output in query somethinhg like this
(wp_postmeta.meta_key = 'passed_key_value' AND CAST(wp_postmeta.meta_value AS CHAR) LIKE '%Array[0], Array[1], Array[2]%'))
According the WP_Query documentation, array is supported in field "value" for meta_query filters.
Attachments (1)
Change History (3)
- Cc r@… added
- Keywords has-patch 2nd-opinion added; needs-patch removed
Here's a first, rough crack at extending the meta query logic to allow an array of values. If a single value is passed, you get the LIKE "%foo%" that you'd expect; if you pass an array of values, you get e.g. LIKE "%foo%" OR LIKE "%bar%".
Would appreciate anyone's thoughts; it feels somewhat dirty at the moment but that's primarily because I didn't want to redo the current logic too much.

The codex just isn't very explicit in the accepted values. A string is expected in all cases, except for IN and BETWEEN (and their NOT counterparts) which both accept an array (or comma separated list of items).
Marking this as an enhancement as such that it's not broken, just not implemented :)