Customize Search box

  • Val Wilson

    #49028

    Hi,

    is there a way to customize the search box widget in Graphene so that it searches only posts and NOT pages?

    Thanks in advance

    Val

    Admin

    Syahir Hakim

    #49060

    The search box in Graphene is the standard WordPress feature. Try searching for a plugin that can restrict WordPress search feature to just posts.

    Val Wilson

    #49082

    Update:

    Adding the code below to functions.php file excludes pages from search

    //Exclude pages from WordPress Search
    if (!is_admin()) {
    function wpb_search_filter($query) {
    if ($query->is_search) {
    $query->set(‘post_type’, ‘post’);
    }
    return $query;
    }
    add_filter(‘pre_get_posts’,’wpb_search_filter’);
    }

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.