I have WP Query and I am simply comparing by the meta value by =
My value contains town names, and seems to work great for the majority of names.
However some names contain apostrophes... Madonna dell'olmo
And the meta values with apostrophes fail to work.
This is my query...
$dealerResults = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'dealer',
'meta_query' => array(
array(
'key' => 'dealer_country',
'value' => $ajaxCounty,
'compare' => '='
),
array(
'key' => 'dealer_location',
'value' => $ajaxTown,
'compare' => '='
)
)
));
I am passing the from a option value through some jquery function and ajax.
foreach($value as $town){
echo "<option class=\"$county_class\" value=\"$town\">$town</option>";
}
-
dealerResults = function () {
var county = $('#dealer-county').val(),
town = $('#dealer-town').val(),
wp_nonce = '<?php echo wp_create_nonce("dealer_search");?>';
if(county != 0 && town != 0){
$.ajax({
type: 'POST',
url: '<?php echo admin_url('admin-ajax.php'); ?>?r='+Math.random(),
data: { varCounty : county, varTown : town, action: 'dealer_search', nonce: wp_nonce },
success: function(data){
$(".dealer-wrapper").remove();
$("#dealer-results").append(data);
}
});
}
}
-
$ajaxCounty = $_POST['varCounty'];
$ajaxTown = $_POST['varTown'];
My question is how can I get the query to work for my meta values which contain apostrophes?
Thanks in advance