Posted on

Relevanssi and Polylang

Relevanssi has an option that restricts the multilanguage searches to just current language. With Polylang, that setting doesn’t actually do anything. Polylang always restricts the searches to the current language. If you want to remove that restriction, you need to disable the taxonomy setting Polylang adds to the searches. You can do it with this small function, placed in the theme functions.php:

add_filter('relevanssi_modify_wp_query', 'rlv_remove_polylang');
function rlv_remove_polylang($q) {
	$q->tax_query = "";
	$q->set('taxonomy', null);
	$q->set('term', null);
	return $q;
}

Do note that this function will wipe out all taxonomy parameters, so if there’s a taxonomy parameter you need to have, that too will be gone. It is possible to make this function a bit more sophisticated, but that is left as an exercise for the reader.