• Resolved akarimi

    (@akarimi)


    Hello,

    I apologize if this has already been asked but I could not find an answer to this:
    I would like to exclude published newsletters from site search. So therefore, when a person searches for a term that exists in both my posts and my newsletter, to not show the newsletter in the site search…it looks a bit tacky and cluttered.

    Is there a way to do this or perhaps add this function in the next release?

    Thanks

    http://wordpress.org/extend/plugins/alo-easymail/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author eventualo

    (@eventualo)

    I tried this piece of code and it worked for me.
    You have to write the “whitelist” of post types for search:

    function set_search_types($query) {
    	if ($query->is_search)
    	{
    		$query->set('post_type', array('post','page') ); // set post types here
    	}
    	return $query;
    }
    add_filter('pre_get_posts', 'set_search_types');

    Thread Starter akarimi

    (@akarimi)

    where does this code go? in the functions.php i assume? – sorry i’m new to this. and by setting my whitelist do you mean the post# for the posts that I want to show in the search? so basically in the array just type my post numbers separated by commas? is there a way to filter the actual post type?

    Thanks

    Thread Starter akarimi

    (@akarimi)

    Nevermind, got it. Thanks! works like a charm

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude published newsletters from site search’ is closed to new replies.