Categories
Code WordPress

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');