To remove the pages from the search results, use the following code:
/* Remove pages from search results */ function SearchFilter($query) { // Check if query is search if ($query->is_search) { // Add the wanted post type $query->set('post_type', 'post'); } // Return the query return $query; } add_filter('pre_get_posts','SearchFilter');