[wp-trac] [WordPress Trac] #42746: Custom query using LIKE compare method adds weird hash-like strings around search string

WordPress Trac noreply at wordpress.org
Wed Nov 29 12:57:25 UTC 2017


#42746: Custom query using LIKE compare method adds weird hash-like strings around
search string
--------------------------+-----------------------------
 Reporter:  ragingtroll   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  4.9
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 below is my test.php file code

 {{{#!php
 <?php
         require_once("wp-load.php");

         $query = "test.query";

         $args = array(
                 'part_title' => $query,
                 'post_type' => 'product',
                 'post_status' => 'publish',
                 'posts_per_page' => 5,
                 //'orderby' => 'title',
                 'orderby' => 'none',
                 'order' => 'ASC',
         );

         $args['meta_query']['relation'] = 'AND';
         $args['meta_query'][] = array(
                 'key'     => 'wpcf-tecdoc',
                 'value'   => 1
         );

         $args['meta_query'][] = array(
                 'key'     => 'wpcf-part-number',
                 //'value'   => preg_quote($query), /* workaround to get
 query%, because compare=LIKE gives %query% */
                 'value'   => $query,
                 'compare' => 'LIKE'
         );

         $wp_query = new WP_Query($args);
         var_dump($wp_query->request);
         die();
 }}}

 outputs something similar to:

 LIKE
 '{632c0741f4b27a83907ceef3c216758d6b81152b5561e7c069c6463b3a041dc7}test.query{632c0741f4b27a83907ceef3c216758d6b81152b5561e7c069c6463b3a041dc7}'

 instead of

 LIKE 'test.query'

 making my query find zero results. If i replace LIKE compare method with
 RLIKE and use  'test.query', the resulting query works as expected, and
 finds the right results.

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


More information about the wp-trac mailing list