Posted on

Relevanssi and Polylang

DEPRECATED: Starting from Relevanssi Premium 2.0 and the free version 4.0, this is no longer necessary. There’s a setting for this in Relevanssi settings panel, under Searching.

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.

2 comments Relevanssi and Polylang

  1. With the new option “Polylang – Allow results from all languages.” in the Premium version 2, is it still necessary to insert the function, or not longer? I had inserted it, it didn’t work. Then I discovered the option in the control panel, checked it, and it worked instantly. Really nice!
    Please, kindly advise if the trick above is still relevant or now obsolete. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *