Exclude Events from Site Search Results

Home Forums Calendar Products Events Calendar PRO Exclude Events from Site Search Results

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #973992
    Car McGinley
    Participant

    I would like to adjust me front end site search functionality so it does not include calendar events. I tried using the code mentioned in this post, but that also removed all pages from search results… Only blog posts came up in search on both the front and back end.

    Here’s what I’d like:

    Front-end search: only pages and blog posts (no calendar events)
    Back-end search: no exclusions at all

    Is this possible? I would appreciate any help you can offer.

    Thanks!
    Nick

    #974033
    Brian
    Member

    Hi Nick,

    I can help out here.

    That snippet was designed to just use posts for search.

    This is an updated version that will enable pages too.

    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');

    Let me know how that works out.

    Thanks

    #974083
    Car McGinley
    Participant

    Hi Brian,

    Thanks for the code suggestion. I pasted it into my functions.php file, but it seems to break the website. I get this error:

    Parse error: syntax error, unexpected ‘&’ in /home/isthmus/www/holywisdom/wp-content/themes/x-child/functions.php on line 76

    I don’t know PHP, so I can’t detect the syntax error. Could you please take a look and perhaps ID the bug?

    Thanks!
    Nick

    #974111
    Brian
    Member

    It is hard to say what the issue is there is no & in the snippet so looks like you put it inbetween two functions.

    Can you put it all the way at the end of the file, but before any closing php tag ( ?> ) That is about all I can suggest on this.

    #986962
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Exclude Events from Site Search Results’ is closed to new replies.