Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#43445 new defect (bug)

Wildcard `LIKE` support for `WP_Meta_Query` (and maybe other queries?)

Reported by: boonebgorges's profile boonebgorges Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Query Keywords:
Focuses: Cc:

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:

  1. 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
  2. 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.

Change History (1)

#1 @boonebgorges
7 years ago

Closely related: #23373

Note: See TracTickets for help on using tickets.