Tag Archives: indexing

Restricting the indexing to particular user roles

From the Relevanssi settings, you can only choose whether subscribers are indexed or not. If you need finer control over what user roles are indexed by Relevanssi, you can use the following code. Place it in your theme functions.php: add_filter(’relevanssi_user_index_ok’, ‘rlv_do_not_index_admins’, 10, 2); function rlv_do_not_index_admins($do_index, $user) { $block_these_roles = array(’administrator’, ‘editor’, ‘author’, ‘contributor’, ‘subscriber’);   […]

Excluding posts by taxonomy

Relevanssi has a category exclusion feature built in, but that only works for basic categories and not any other taxonomies. You can use tax_query to restrict the searches as well, but that’s more complicated than adjusting the setting in Relevanssi settings. However, if the exclusion is permanent, it’s best done in the indexing level. That […]

Deindexing Yoast SEO noindex posts

If you use Yoast SEO to mark posts “noindex”, you may want to have Relevanssi deindex those posts as well. It’s easy to do using the relevanssi_do_not_index hook. Just add this function to your theme functions.php: add_filter(’relevanssi_do_not_index’, ‘rlv_yoast_noindex’, 10, 2); function rlv_yoast_noindex($do_not_index, $post_id) { $noindex = get_post_meta($post_id, ‘_yoast_wpseo_meta-robots-noindex’, true); if ($noindex) $do_not_index = true; return […]

Excluding protected posts

A site I’m working with has a handful of “protected” posts (password required to view). For various reasons, we don’t want to show these in search results. While there is no excerpt shown, I’d prefer for people to not even know they exist. Relevanssi sees protected posts as public posts (because their post status is […]

Indexing attachment filenames

Relevanssi has been working nicely for the normal usecase. But how does one setup indexing of attachment files. When someone searches by filename or extension like pdf, there are no results. I have enabled ‘attachment’ at Relevanssi ‘Indexing options’ and still there are no results. Relevanssi doesn’t index attachment file names. For attachments, Relevanssi indexes […]

Searching by post ID

Are post ID’s searchable in Relevanssi? No. Relevanssi does understand the WP_Query p parameter to restrict the search by post ID. However, if you want to search by post ID, it’s very simple to make that happen: add_filter(’relevanssi_content_to_index’, ‘rlv_index_post_id’, 10, 2); function rlv_index_post_id($content, $post) { $content .= " " . $post->ID; return $content; }add_filter(‘relevanssi_content_to_index’, ‘rlv_index_post_id’, […]