I have a form on a page that search property with a location field and I used the following meta query to process the search;
$location = preg_replace('/^-|-$|[^-a-zA-Z0-9]/', '', $_GET['location']);
$meta_query = array( 'relation' => 'AND' );
if($location) {
$meta_query[] = array(
'relation' => 'OR',
array(
'key' => 'property_country',
'value' => $location,
'compare' => 'LIKE'
),
array(
'key' => 'property_city',
'value' => $location,
'compare' => 'LIKE'
),
array(
'key' => 'property_location',
'value' => $location,
'compare' => 'LIKE'
)
);
}
However, it works fine if I search for New but returns no results if I search for New York. How can I resolve this? Is there a way to add a wildcard before and after the $location
? I tried adding '*'.$location.'*'
but that did nothing.