This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Add condition to "asp_query_args"

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Add condition to "asp_query_args" Reply To: Add condition to "asp_query_args"

#25589
Ernest MarcinkoErnest Marcinko
Keymaster

Hi Nicolas,

I made an adjustmend to your code, now you can enter the search IDs to the $exclude_ids array, to which you don’t want the code to execute:

add_filter('asp_query_args', 'map_search_phrase', 10, 2);
function map_search_phrase($args, $search_id) {
	// search IDs to exclude
	$exclude_ids = array(13, 14);
	
	if ( !in_array($search_id, $exclude_ids) ) {
		$args['s'] = mb_strtolower($args['s']);
		$mapping = array(
			"calculs" => "calcul",
			"rénaux" => "rénal",
			"rénale" => "rénal",
			"génitales" => "génitale",
			"génital" => "génitale",
			"génnitales" => "génitale",
		);
		$initial = array();
		$replace = array();
		foreach ($mapping as $k => $v) {
			$initial[] = "/\b".preg_quote($k)."\b/u";
			$replace[] = $v;
		}
		$args['s'] = preg_replace($initial, $replace, $args['s']);
	}
	return $args;
}