Exclude Events from the WordPress Search results on the frontend.

Home Forums Calendar Products Events Calendar PRO Exclude Events from the WordPress Search results on the frontend.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1325728
    James O’Sullivan
    Participant

    Hi there, When using the standard WP search on the frontend of my site I see all my events past and present showing up. I would prefer no events showing up at all actually and just my posts and pages. How can I exclude all events from showing.

    Any help would be much appreciated.

    Thanks,
    James

    #1326652
    Victor
    Keymaster

    Hello James!

    Thanks for getting in touch with us! Let me help you with that.

    Try placing the following code snippet into your theme’s functions.php file:

    function exclude_from_search($query) {
    if ($query->is_search) {
    $query->set('post_type', 'post');
    }
    return $query;
    }
    add_filter('pre_get_posts','exclude_from_search');
    

    Let me know if that works for you! 🙂

    Best,
    Victor

    #1327439
    James O’Sullivan
    Participant

    Thank you kindly Victor this did the trick.

    #1327447
    Victor
    Keymaster

    Glad to know it worked out for you James! 🙂 Thanks for letting me know.

    I’ll close this now, but don’t hesitate to open a new thread if anything comes up.

    Cheers!
    Victor

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Exclude Events from the WordPress Search results on the frontend.’ is closed to new replies.