this is my code:
$terms = wp_get_post_terms( $listing_id,'job_listing_category' );
if(!empty($terms)){
$sql_terms.=" AND (";
foreach($terms as $term){
$sql_terms.=" category LIKE '%".$term->slug."%' OR";
}
$sql_terms.=" category IS NULL OR category=''";
$sql_terms.=") ";
}
$wpdb->get_results(
$wpdb->prepare(
"SELECT DISTINCT user_id ,proximity,
( %s * IFNULL( acos( cos( radians(lat) ) * cos( radians( %s ) ) * cos( radians( %s ) - radians(lng) ) + sin( radians(lat) ) * sin( radians( %s ) ) ), 0 ) )
AS distance
FROM ".$wpdb->prefix."a_filters as f
WHERE
f.notify=1 AND lat!='false' AND lng!='false' AND listing_type='".$listing_type."'
".($sql_terms?$sql_terms:"")."
HAVING distance < proximity
ORDER BY distance ASC"
, $earth_radius, $lat, $lng, $lat)
);
One of the $terms is "special-purpose".
I get error wpdb::prepare was called incorrectly. The query does not contain the correct number of placeholders (5) for the number of arguments passed (4). And that is because it also counts the %s from '%special-purpose%'. How can I make it ignore the %s from '%special-purpose%' ?