$results = new WP_Query( array(
'post_type' => 'questions',
'post_status' => 'publish',
'no_found_rows' => '1',
'nopaging' => '1',
'ignore_sticky_posts' => '1',
'orderby' => 'rand',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'reference-1',
'value' => 'lucht',
'compare' => '='
),
array(
'key' => 'reference-2',
'value' => 'lucht',
'compare' => '='
)
)
));
echo $results->request;
gives:
SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( ( wp_postmeta.meta_key = ‘response’ AND wp_postmeta.meta_value=”lucht” ) OR ( wp_postmeta.meta_key = ‘answers’ AND wp_postmeta.meta_value=”lucht” ) ) AND wp_posts.post_type=”questions” AND ((wp_posts.post_status=”publish”)) GROUP BY wp_posts.ID ORDER BY RAND()
Now replace the meta_query compare = to LIKE:
...
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'reference-1',
'value' => 'lucht',
'compare' => 'LIKE'
),
array(
'key' => 'reference-2',
'value' => 'lucht',
'compare' => 'LIKE'
)
)
...
gives:
SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( ( wp_postmeta.meta_key = ‘response’ AND wp_postmeta.meta_value LIKE ‘{c33232364fb7d50ba632c808436b28560295aade9067a11e1fc4ae1c5879c13d}lucht{c33232364fb7d50ba632c808436b28560295aade9067a11e1fc4ae1c5879c13d}’ ) OR ( wp_postmeta.meta_key = ‘answers’ AND wp_postmeta.meta_value LIKE ‘{c33232364fb7d50ba632c808436b28560295aade9067a11e1fc4ae1c5879c13d}lucht{c33232364fb7d50ba632c808436b28560295aade9067a11e1fc4ae1c5879c13d}’ ) ) AND wp_posts.post_type=”questions” AND ((wp_posts.post_status=”publish”)) GROUP BY wp_posts.ID ORDER BY RAND()
The {c33232364fb7d50ba632c808436b28560295aade9067a11e1fc4ae1c5879c13d} seems to be some random value 64 byte value in curly brackets.
Had it been a % instead, the query would work just fine.
I have tested this on two installs on different servers (4.9.5), turned off all plugins.
The question:
Am I doing anything wrong here or should I create a bug ticket?