WordPress.org

Forums

Relevanssi - A Better Search
[resolved] Exclude posts & pages from index (5 posts)

  1. Simon Blackbourn
    Member
    Posted 3 years ago #

    Hi

    I'd like to exclude posts and pages from the index (I only want one custom post type to be searchable) - is this possible, or should I use the relevanssi_hits_filter to remove them from the array of results?

    Thanks
    Simon

  2. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    It's not possible currently, so for now you need to use relevanssi_hits_filter. However, it wouldn't be terribly hard to add option "only these" to the "posts, pages, public, everything" indexing option.

  3. Simon Blackbourn
    Member
    Posted 3 years ago #

    Thanks, here's how I've done it in case it's useful for anyone else:

    add_filter( 'relevanssi_hits_filter', 'my_hits_filter' );
    
    function my_hits_filter( $data ) {
    
    	$hits = $data[0];
    
    	foreach ( $hits as $key => $hit ) {
    		if ( 'post' == $hit->post_type or 'page' == $hit->post_type ) {
    			unset( $hits[$key] );
    		}
    	}
    
    	$filtered_data = array( $hits, $data[1] );
    
    	return $filtered_data;
    
    }

    Cheers
    Simon

  4. raonip
    Member
    Posted 3 years ago #

    Hi,

    Would be great to have this option in the Setting screen! I also would like to Search only ONE Custom Post Type!

    Thanks for this great plugin!

  5. Mikko Saari
    Member
    Plugin Author

    Posted 3 years ago #

    Yeah, it'll be an option in some future version.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Relevanssi - A Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags