Skip to main contentSkip to footer

If Polylang is in use and you haven’t enabled “Media translation“, your attachment files won’t have a language. That’s fine, except when Relevanssi searches fail to find your attachment because they’re looking for posts in a specific language.

Suppose you want to include attachments in Polylang searches. In that case, you can either enable “Media translate” so that your media files have a language, or you can use this code in your theme functions.php to always include attachments in the results:

add_filter(
	'relevanssi_where',
	function( $query ) {
	  global $wpdb;
	  
	  $query  = str_replace( 'AND relevanssi.doc', 'AND ( relevanssi.doc', $query );
	  $query .= ' OR relevanssi.doc IN (
	  		SELECT DISTINCT(ID) FROM ' . $wpdb->posts . ' WHERE post_type = "attachment"
		) OR relevanssi.doc = -1 )';
  
	  return $query;
	}
);

This function hooks onto the relevanssi_where filter hook to modify the Polylang taxonomy query so that the search always includes the attachments. This only works if the query uses no other query variables except the Polylang language query. The results may be unexpected if there are other query filters applied.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Multisite searches

Multisite search only works in Relevanssi Premium. Free Relevanssi can be installed in multisite environments, but it cannot search across sites. Relevanssi Premium can only support multisite searching across sites in the same multisite network. Relevanssi can’t search across multiple sites that are not in the same multisite installation. Cloud-based……other hand, you can adjust the settings for each blog. Enabling the multisite search There are several ways to enable multisite searching. If you want all searches to be multisite searches, you can enable multisite searching from the Relevanssi searching settings. If you want only some searches to be multisite…) { switch_to_blog( $post->blog_id ); } } add_action( ‘astra_page_template_parts_content’, ‘rlv_blog_restore’, 9999 ); add_action( ‘astra_template_parts_content’, ‘rlv_blog_restore’, 9999 ); function rlv_blog_restore() { restore_current_blog(); } Multisite search finds nothing? Relevanssi by default does not search non-public blogs. If you’re developing your multisite network and the sites are not set as public yet, Relevanssi…

CM Tooltip Glossary
A Relevanssi Premium customer bumped into a weird problem with CM Tooltip Glossary (and probably Elementor). Using Elementor, CM Tooltip…
Relevanssi and languages

Relevanssi is language-agnostic in itself. It does not know any language and doesn’t care about which language the site uses. However, there are a few things that you need to consider when using Relevanssi in languages other than English. Characters: use UTF8 As long as your site uses UTF8 characters,……mean” suggestions in Relevanssi Premium only support Latin characters. The way these suggestions work is that when Relevanssi searches, Relevanssi then modifies the search term in different ways by adding or removing letters in it. Relevanssi does these modifications with the Latin alphabet (mainly the English alphabet, with a few…

Related Posts:

Comment Section:

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed