Return to Support

Search Widget

Home Forums Graphene WordPress theme Support Search Widget

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #2721
    sylvia
    Member

    Is there a way to limit the search widget to only searching posts……and not pages. Almost every type of search that I try on my site usually includes my “Terms of Service” page in the search results. I only want the search results to display post content and not page content…is this possible?

    #21629
    Prasanna SP
    Member

    Put this to your child theme’s functions.php file (If you don’t know how to modify child theme functions, you may read this – How to modify the theme using a child theme)

    function searchfilter($query) {

    if ($query->is_search) {
    $query->set('post_type',array('post'));
    }

    return $query;
    }

    add_filter('pre_get_posts','searchfilter');

    #21630
    soapy
    Member

    Prasanna,

    THANK YOU!

    #21631
    Prasanna SP
    Member

    Did that work?? If it’s working, please mark this thread as resolved..

    #21632
    soapy
    Member

    I’m just uploading right now….I’ll let you know in 5 mins….

    #21633
    Prasanna SP
    Member

    Okay, what’s the URL of your site?

    #21634
    soapy
    Member

    No…it did not work….here is a copy of my functions.php file. This is the first time I made a functions.php file to put in my child theme folder so i’m not sure if i did this correctly…..

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    function searchfilter($query) {

    if ($query->is_search) {
    $query->set('post_type',array('post'));
    }

    return $query;
    }

    add_filter('pre_get_posts','searchfilter');

    </body>
    </html>

    #21635
    soapy
    Member

    It actually started displaying the code all over my dashboard in wordpress…..

    #21636
    Prasanna SP
    Member

    No! it’s not the HTML code. It’s php. So put codes between <?php and ?>

    Put this in functions.php

    <?php
    function searchfilter($query) {

    if ($query->is_search) {
    $query->set('post_type',array('post'));
    }

    return $query;
    }

    add_filter('pre_get_posts','searchfilter');
    ?>

    #21637
    soapy
    Member

    ok give me a minute here and i’ll let u know…thanks again…

    #21638
    soapy
    Member

    Thank you Prasanna, it works great! Thanks again!

    #21639
    Prasanna SP
    Member

    You’re Welcome! 🙂

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

You must be logged in to reply to this topic.