Make WordPress Core

Opened 4 years ago

Last modified 5 months ago

#58180 new enhancement

Specify the REGEXP format for meta_query

Reported by: letraceursnork Owned by:
Priority: normal Milestone: Awaiting Review
Component: Database Version: 6.2
Severity: trivial Keywords: needs-docs dev-feedback has-patch
Cc: Focuses:

Description

Because of the fact that meta_query parameter with ['compare' => 'REGEXP', 'key' => 'foo', 'value' => '^bar'] working as substitution to raw SQL-request like ... foo.meta_key REGEXP ^bar ...
please, specify this explicitly in the ​documentation - especially the fact that this REGEXP should not be wrapped in /

Change History (3)

#1 @letraceursnork
3 years ago

@SergeyBiryukov check this out pls

#2 @letraceursnork
12 months ago

Check this out somebody pls

This ticket was mentioned in ​PR #12072 on ​WordPress/wordpress-develop by ​@patrickfl.


5 months ago
#3

  • Keywords has-patch added

When a meta_query clause uses 'compare' => 'REGEXP' (or 'NOT REGEXP' / 'RLIKE'), the value is passed directly to MySQL's REGEXP operator. This is not obvious from the DocBlock, and a common mistake is to wrap the pattern in PCRE-style delimiters (e.g. /^bar/), which MySQL treats as literal characters.

This adds a note to the $value parameter in the WP_Meta_Query DocBlock clarifying that for the REGEXP-family compares the value is used as a raw MySQL regular expression and should not be wrapped in delimiters such as /.

Documentation only; no behavioral change.

Props letraceursnork.
Fixes #58180.

Note: See TracTickets for help on using tickets.