If you want to force the search engine to search only within a specific post type, then all you have to do is simply copy and paste the following code into your theme’s functions.php file. Remember to change the post type name on line 4 and you are done.
1 2 3 4 5 6 7 8 9 10 | function SearchFilter($query) { if ($query->is_search) { // Insert the specific post type you want to search $query->set('post_type', 'feeds'); } return $query; } // This filter will jump into the loop and arrange our results before they're returned add_filter('pre_get_posts','SearchFilter'); |
Snippet Source/Credit: Hongkiat