Opened 7 years ago
Closed 7 years ago
#42746 closed defect (bug) (duplicate)
Custom query using LIKE compare method adds weird hash-like strings around search string
Reported by: | ragingtroll | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.9 |
Component: | Query | Keywords: | |
Focuses: | Cc: |
Description
below is my test.php file code
<?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.
Change History (1)
Note: See
TracTickets for help on using
tickets.
After WordPress 4.8.3 this is expected.
Please see the comments on #42653 and #42409 for adding support for using
LIKE
againstmeta_key
(You've probably got another filter somewhere on the SQL which is now failing, which wasn't included in the ticket details)