Exclude pages in WordPress search result
If you want to exclude pages in search result i WordPress you just this to your functions.php.
If you just want to search for pages instead of posts you just change ’post’ to ’page’.
function add_search_filter( $query ) { if ( $query->is_search ) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts', 'add_search_filter');