How do I remove Pages from search?

I don’t need to search for pages in my site and only want to search posts, is there a way to do it? Thanks


The below should make the page post type no longer search-able.

function remove_pages_from_search() {
    global $wp_post_types;
    $wp_post_types['page']->exclude_from_search = true;
add_action('init', 'remove_pages_from_search');

Leave a Comment