Preventing Listings from appearing in WordPress search

This topic contains 3 replies, has 2 voices, and was last updated by  Guust 8 years, 11 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #66123

    visitmcminnville
    Expired Member
    Post count: 7

    Hi There!

    We integrated GeoDirectory with our WordPress website built on Avada. Right now, when Avada’s “search” bar is used on the home page it brings up listings from GeoDirectory. We were wondering if it’s possible to prevent the GeoDirectory listing from appearing on that search page as we were hoping it would only work for other Blog posts & pages.

    We installed the advanced search for GeoDirectory that works great on the listing page already which is why we would like it separate. Hope that makes sense!

    Please let me know if this is possible. Thanks!!

    #66124

    Guust
    Moderator
    Post count: 29970

    Try adding this to your functions.php file

    
    
    function searchfilter($query) {
        if ($query->is_search && !is_admin() ) {
            $query->set('post_type',array('post','page'));
        }
    return $query;
    }
    add_filter('pre_get_posts','searchfilter');
    #66125

    visitmcminnville
    Expired Member
    Post count: 7

    That worked. Thank you very much!!

    #66126

    Guust
    Moderator
    Post count: 29970

    You’re welcome 🙂

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

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount