I’m currently working on a search function in a wp site. The plan is to have a search function on the news page which just searches posts.
I’m achieving this by adding the below to my functions.php file:
/* search just posts */
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
which works fine. BUT. I also need to create a search on a custom post type listing – for just the custom posts and also one for the entire site to live on the 404 page.
Any ideas how to go about this greatly appreciated?
you can change your search filter to this:
then on your news search form add :
on your custom post type listing search form add
and on the entire site search for don’t add anything
an you are set.