[wp-trac] [WordPress Trac] #53450: [WP_Meta_Query] Add faster LIKE based 'STARTSWITH' and 'ENDSWITH' compare modes for value query

WordPress Trac noreply at wordpress.org
Fri Feb 25 23:09:19 UTC 2022


#53450: [WP_Meta_Query] Add faster LIKE based 'STARTSWITH' and 'ENDSWITH' compare
modes for value query
-------------------------------------------------+-------------------------
 Reporter:  janthiel                             |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  Query                                |     Version:  5.7.2
 Severity:  trivial                              |  Resolution:
 Keywords:  dev-feedback has-patch needs-docs    |     Focuses:
  needs-codex has-unit-tests early early-like-   |  performance
  actually-early                                 |
-------------------------------------------------+-------------------------

Comment (by janthiel):

 Regarding example code:
 Let's stick with the Stack Overflow questions regarding "WordPress Meta
 Query Startswith" / "- Endswith".

 Just picked some of them which seem relevant to me:

 https://wordpress.stackexchange.com/a/159433
 https://wordpress.stackexchange.com/q/178302

 The "Email" example is a good one:

 Task: Get all Posts / Users where the email address stars- or ends with
 something particular.

 Before 6.0.0:

 {{{#!php
     'meta_query' => array(
         array(
             'key'       => 'email_address',
             'value'     => '^hello@',
             'compare'   => 'REGEXP',
         )
     )
 }}}

 Or:

 {{{#!php
     'meta_query' => array(
         array(
             'key'       => 'email_address',
             'value'     => '@example\.com$',
             'compare'   => 'REGEXP',
         )
     )
 }}}

 As of 6.0.0:

 {{{#!php
     'meta_query' => array(
         array(
             'key'               => 'email_address',
             'value'             => 'hello@',
             'compare'           => 'LIKE',
             'compare_like_mode' => 'startswith'
         )
     )
 }}}

 Or:

 {{{#!php
     'meta_query' => array(
         array(
             'key'               => 'email_address',
             'value'             => '@example.com',
             'compare'           => 'LIKE',
             'compare_like_mode' => 'endswith'
         )
     )
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53450#comment:27>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list