Hiding events when using WordPress search

Home Forums Calendar Products Events Calendar PRO Hiding events when using WordPress search

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1206708
    Shaun
    Participant

    Hello, I just brought my site, MedicalTraining.cc live! One thing I noticed while checking its functionality on mobile is that when I search for one of the courses we teach, say, CPR, it brings up huge numbers of events and the page related to CPR is buried. Is there anyway to hide events from my site’s search results?

    Thanks for any assistance!

    Mike

    #1206736
    Hunter
    Moderator

    Hey Mike 🙂

    Congratulations on the new site! If you add the following code to the bottom of your theme’s functions.php file, events should no longer get displayed in your site’s search results. Please try it out and let me know how it works for you. I tested in using the default Twenty Seventeen theme and it worked correctly. Thank you and have a great rest of the day!

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

    #1207059
    Shaun
    Participant

    Perfect solution!

    First easy fix I’ve come across. Have a great day!

    Mike

    #1207261
    Hunter
    Moderator

    Thank you for letting me know the issue has been resolved and please feel free to create a new thread if you have any more questions or comments. Take care!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Hiding events when using WordPress search’ is closed to new replies.