[wp-trac] [WordPress Trac] #40630: Advanced meta compare "like" in WP_Query

WordPress Trac noreply at wordpress.org
Tue May 2 06:28:35 UTC 2017


#40630: Advanced meta compare "like" in WP_Query
------------------------------+-----------------------------
 Reporter:  sebastian.pisula  |      Owner:
     Type:  defect (bug)      |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Query             |    Version:
 Severity:  normal            |   Keywords:
  Focuses:                    |
------------------------------+-----------------------------
 I try get posts with LIKE compare. For example:
 {{{#!php
 <?php
 add_action( 'init', function () {
         $q = new WP_Query(
                 [
                         'post_type'    => 'any',
                         'meta_key'     => '_stock_status',
                         'meta_value'   => 'i%st',
                         'meta_compare' => 'LIKE',
                 ]
         );
 } );
 }}}

 And I have SQL Query:


 {{{
 SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts  INNER JOIN
 wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1  AND (
   ( wp_postmeta.meta_key = '_stock_status' AND wp_postmeta.meta_value LIKE
 '%i\\%st%' )
 ) AND wp_posts.post_type IN ('post', 'page', 'attachment', 'product') AND
 (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY
 wp_posts.post_date DESC LIMIT 0, 10
 }}}

 I can't get posts with meta value for example `instock` and other matched.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40630>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list