How to include or exclude pages or posts from WordPress search result
How to include or exclude pages or posts from WordPress search result
Display specific posts in the 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
Exclude From Search = True
from advanced options

Post a Comment