Make WordPress Core

Opened 13 years ago

Closed 10 years ago

#18707 closed enhancement (wontfix)

Meta Query printing "array" in query when compare type is LIKE

Reported by: tplayer's profile tplayer Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Query Keywords: has-patch needs-testing meta-query needs-refresh
Focuses: Cc:

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 (2)

multiplelikes.18707.diff (1.7 KB) - added by robmiller 12 years ago.
First go at allowing multiple LIKE values in a meta query
18707.diff (1.6 KB) - added by wonderboymusic 12 years ago.

Download all attachments as: .zip

Change History (9)

#1 @dd32
13 years ago

  • Type changed from defect (bug) to enhancement

According the WP_Query documentation, array is supported in field "value" for meta_query filters.

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 :)

@robmiller
12 years ago

First go at allowing multiple LIKE values in a meta query

#2 @robmiller
12 years ago

  • 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.

Usage: new WP_Query(array('meta_key' => 'foo', 'meta_value' => array('foo', 'bar'), 'meta_compare' => 'like'));

Last edited 12 years ago by robmiller (previous) (diff)

#3 @wonderboymusic
12 years ago

  • Keywords needs-testing added; 2nd-opinion removed

Patch needs testing and I shudder to think how badly multiple wildcard searches will perform with meta query. Not ready to move this over.

#4 @wonderboymusic
11 years ago

  • Keywords meta-query added

#5 follow-up: @wonderboymusic
11 years ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to Future Release

This does make some sense from an API perspective - my performance concerns are still vast

#6 @SergeyBiryukov
11 years ago

  • Summary changed from Meta Query printing "array" in query whwn compara type is LIKE to Meta Query printing "array" in query when compare type is LIKE

#7 in reply to: ↑ 5 @boonebgorges
10 years ago

  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Replying to wonderboymusic:

This does make some sense from an API perspective - my performance concerns are still vast

If someone wants to join a half dozen LIKE clauses, they can already do it. The new proposed syntax makes it marginally easier to inflict pain on oneself, but IMO this is not a serious concern.

More serious is that LIKE + an array is ambiguous between OR and AND. #27344 proposes some additional syntax to handle that, but in https://core.trac.wordpress.org/ticket/27344#comment:4 I rain on that parade too. Short story: anything you want to do with the proposed array syntax can be accomplished without it, especially since [29887].

I'm going to close this ticket because it's covered by #27344, which I think should also be closed. robmiller - thanks so much for the patch.

Note: See TracTickets for help on using tickets.