Support » Plugin: Relevanssi - A Better Search » exlude by tag?

  • Resolved catsfoto1se

    (@catsfoto1se)


    hi!
    I saw that its possible to exclude posts by category.
    in my system users can set a tag “dont list me”, is there any function for preventing the search to find them, like an exclude for tags.

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

    (@msaari)

    Go to Relevanssi settings in the admin dashboard, click the “Help” on the top right corner of the page, and see “Exclusions”. There’s a bit of code you can use to exclude tagged posts during indexing.

    Thx, that’s great, ehum, for a WordPress newbie, where should I add the filter hook code?, What file?

    Plugin Author Mikko Saari

    (@msaari)

    Theme functions.php is a very good place.

    Then i will do so, thx

    Didn’t get it to work.

    I added:

    add_filter( 'relevanssi_do_not_index', 'rlv_index_filter', 23, 2 );
    function rlv_index_filter( $block, $post_id ) {
    	if ( has_term( 'jazz', 'genre', $post_id ) ) {
    		$block = true;
    	}
    	return $block;

    In my theme functions.PHP

    And the tag I’d is 23, it still index it.

    And what does the word jazz and genre do in the code?

    I even tried to change from jazz to the name of the tag that was going to be excluded, but the same result

    A tip to help us newbies, is to explain what in a code that we need to change..

    • This reply was modified 1 year, 4 months ago by catsfoto1se.
    Plugin Author Mikko Saari

    (@msaari)

    “jazz” is the name of the taxonomy term, “genre” is the taxonomy. So now you’re blocking all documents which have the “genre” set to “jazz”.

    If your tag name is “don’t list me” and it’s a regular tag, you have:

    add_filter( 'relevanssi_do_not_index', 'rlv_index_filter', 10, 2 );
    function rlv_index_filter( $block, $post_id ) {
    	if ( has_term( "don't list me", 'post_tag', $post_id ) ) {
    		$block = true;
    	}
    	return $block;
    }

    Hey! It worked!

    kiitos paljon

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘exlude by tag?’ is closed to new replies.