Display specific posts in search result

function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}

add_filter('pre_get_posts','SearchFilter');

also we can set

$query->set('cat','8,15');
$query->set('post_type', array('video-camera', 'software-solution','post') ); // id of page or post

If we are Custom Post Types plugin than edit custom post and set
Exclude From Search = True
from advanced options

Advertisements