WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Exclude posts & pages from index

[Resolved] Exclude posts & pages from index

  • 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

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

    @msaari

    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.

    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

    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!

    Plugin Author Mikko Saari

    @msaari

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Exclude posts & pages from index’ is closed to new replies.