• Is it possible to use custom taxonomy terms in the Category Exclusion list on the Search tab? I added a custom taxonomy to media attachments using a plugin. I added a term which I’d like to use to exclude certain media files from search results. But I don’t see this term listed in the Category Exclusion list.

Viewing 1 replies (of 1 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yeah, that list is only for the “Category” taxonomy. If you want to exclude by custom taxonomy, you have to do it in a different way. There are some instructions in the Relevanssi contextual help (click “Help” on the top right of Relevanssi settings page), but if you want the restriction to apply in all searches, this is the best way:

    add_filter( 'relevanssi_do_not_index', 'rlv_index_filter', 10, 2 );
    function rlv_index_filter( $block, $post_id ) {
    	if ( has_term( 'TERM_NAME', 'TAXONOMY_NAME', $post_id ) ) {
    		$block = true;
    	}
    	return $block;
    }

    Add this to your theme functions.php, replace TERM_NAME with the name of the term (the slug) and TAXONOMY_NAME with the name of the taxonomy. Then rebuild the index.

    Now the posts you want to exclude are excluded already in the indexing, so there’s no chance they’ll ever show up in search results.

Viewing 1 replies (of 1 total)
  • The topic ‘excluding post based on custom taxonomy term (relevanssi))’ is closed to new replies.