• Resolved princejohny

    (@princejohny)


    Hello!

    I wanted to know how to exclude everything besides post that are specifically tagged from the search results

    I tried using the exclusion feature but didn’t work

    Any suggestions?

    Thanks!

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

    (@msaari)

    How exactly are the specific posts tagged? With a regular tag?

    If the posts are never to be found in search, it’s best to not index them in the first place. That’s best done with a relevanssi_indexing_restriction filter function that will block the posts from being indexed.

    Relevanssi manual for filter hooks is here.

    Thread Starter princejohny

    (@princejohny)

    Wow,
    Thanks for the fast response and thank you for the info, I also should’ve said what we are trying to accomplish

    We built a page for daily news using elementor and put a search bar. We want the search bar to only display results for other news articles so we tagged them with a regular tag we also put it in its own category

    So should I continue and read the manual filter hooks or is there an easier way to only include that category?

    Plugin Author Mikko Saari

    (@msaari)

    So you only want to include news posts in the results? If that’s the case, add this code to your theme functions.php and Relevanssi will only index posts in a specific category:

    add_filter( 'relevanssi_indexing_restriction', 'rlv_only_index_category_x' );
    function rlv_only_index_category_x( $restriction ) {
    	global $wpdb;
    	$restriction['mysql']  .= " AND post.ID IN (SELECT tr.object_id FROM $wpdb->term_relationships AS tr, $wpdb->term_taxonomy AS tt WHERE tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.term_id = X ) ";
    	$restriction['reason'] .= ' Not in the right category';
    	return $restriction;
    }

    Replace the X in the query with the category ID of the news category. Now when you build the index, only news posts are included.

    Thread Starter princejohny

    (@princejohny)

    it worked, I spent 4 weeks on this. I can’t thank you enough!

    Plugin Author Mikko Saari

    (@msaari)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Excluding search results’ is closed to new replies.