[wp-trac] [WordPress Trac] #42409: Add LIKE support to meta_key comparisons in WP_Meta_Query

WordPress Trac noreply at wordpress.org
Mon Nov 20 22:06:37 UTC 2017


#42409: Add LIKE support to meta_key comparisons in WP_Meta_Query
-------------------------------------------------+-------------------------
 Reporter:  Otto42                               |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Database                             |  Review
 Severity:  normal                               |     Version:  4.9
 Keywords:  good-first-bug needs-unit-tests      |  Resolution:
  has-patch                                      |     Focuses:
-------------------------------------------------+-------------------------

Comment (by chasewg):

 Submitted a unit test for this using a diff patch. Tried Following the
 contributor handbook, but I'm still not sure if I followed the correct
 process--so any comments/corrections are greatly appreciated!

 {{{#!php
 <?php
 public function test_compare_meta_key(){
             global $wpdb;
             $meta_key='foo_bar';
             $q=new WP_Meta_Query([array(
                 'compare_key'=>'LIKE',
                 'key'=>$meta_key
                     )]);
             $sql=$q->get_sql('post', $wpdb->posts, 'ID', $this);

             $this->assertRegexp("/{$wpdb->postmeta}\.meta_key LIKE
 %{$wpdb->esc_like($meta_key)}%/", $sql['where']);

         }

 }}}

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


More information about the wp-trac mailing list