In WordPress by default both posts and pages are included in the Search Results, you can remove pages or posts for that matter and also include custom post types by using the action hook pre_get_posts.

In your functions.php add the appropriate snippet;

To remove pages from the search results add in…

View the code on Gist.

To remove posts from the search results add in…

View the code on Gist.

To add in custom post types to the search results add in

View the code on Gist.

In the last code snippet we are passing in an array of different post types, just adjust the names of them to suit your needs.

Share:

Leave a Reply