Exclude pages from wordpress search

If you want to exclude wordpress pages from the search then you have to add following code in your themes function.php file.

    function SearchFilter($query) {
    if ($query->is_search) {
    $query->set('post_type', 'post');
    return $query;


Above code filters all the posts retrieved by the wordpress query and set post_type equal to “post”.


WordPress Filters

Leave a Reply

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