I am using the following code:
$tolettpe = "Sale";//default
if($_REQUEST['tolettype']) $tolettpe = $_REQUEST['tolettype'];
else if($_REQUEST['srch_type']) $tolettpe = $_REQUEST['srch_type'];
$args = array(
'numberposts' => $latestcount,
'category' => $catidstr,
'meta_key' => 'property_type',
'meta_compare' => 'LIKE',
'meta_value' => $tolettpe.'%'
);
$post_content = get_posts($args);
The value in the database is ‘Sale||’ and there are no query string variables in the request.
But the query returns no results.
If I use the exact value and no meta_compare, it works.
Any ideas how to make this work?
meta_compare
Possible values are'!=', '>', '>=', '<', or '<='
. Default value is'='
if you want to use
LIKE
you need to create a meta_query eg:The generated query puts the search term between two % signs, so there is no need to add any in the code.