WordPress: Exclude Pages from Search Results

Add the following to your functions.php file to exclude pages from the search results of your WordPress blog.

//Filter out pages from search results
function search_exclude_pages($query) {
 if ($query->is_search) {
 $query->set('post_type', 'post');
 }
 return $query;
}
add_filter('pre_get_posts','search_exclude_pages');

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: