[wp-trac] [WordPress Trac] #19738: meta_query should check for wildcards when using LIKE operator

WordPress Trac wp-trac at lists.automattic.com
Wed Jun 13 22:44:35 UTC 2012


#19738: meta_query should check for wildcards when using LIKE operator
-------------------------+------------------------------
 Reporter:  ejdanderson  |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Query        |     Version:  3.2
 Severity:  normal       |  Resolution:
 Keywords:  2nd-opinion  |
-------------------------+------------------------------
Changes (by SpaceMacGyver):

 * cc: SpaceMacGyver (added)


Comment:

 While I appreciate the need to abstract the SQL away from the query, as
 ejdanderson suggests a flag to control this would indeed be the
 appropriate means of handling this.  As a stopgap measure, though, a
 filter on '''get_meta_sql''' to modify the WHERE clause should hopefully
 address this (example code provided below to remove the first % from the
 LIKE condition):

 {{{
 function remove_sql_wildcard_prefix($q)
 {
         $q['where'] = preg_replace("/(LIKE ')%(.*?%')/", "$1$2",
 $q['where']);
         return $q;
 }
 add_filter('get_meta_sql', 'remove_sql_wildcard_prefix');
 }}}

 (disclaimer: the provided code is not yet tested, but in theory I think it
 works)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/19738#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list