Search filter (wordpress)

Exclude pages from search results.

<?php
/**
 * Exclude pages from search results.
 */
add_filter('pre_get_posts', function($query) {
    if (!is_admin() && ($query->is_search)) {
        $query->set('post_type', 'post');
    }
    return $query;
});
?>

functions.php

< toolbox