Exclude Event Category from Calendar but NOT custom Query

Home Forums Calendar Products Events Calendar PRO Exclude Event Category from Calendar but NOT custom Query

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1128160
    Glen Draeger
    Participant

    It’s fairly easy to exclude a category globally using code from forum using the hook:

    pre_get_posts

    However, on the main calendar pages I’m running a custom slider using events. I want all categories to show in the slider but not in any of the calendar views below it. When I use pre_get_posts it effects not only the calendar, but my slider too removing the category from both.

    Is there some way to only remove the category without removing it from my slider too?

    #1128168
    Geoff
    Member

    Hey @glendraeger,

    Yeah, that’s totally possible!

    Here’s an example of a snippet that removes events in categories named “concert” and “dance”:
    https://gist.github.com/geoffgraham/247cf5d7c7e618a60db9

    Note that it is currently targeting the List and Month views only, so you can modify that to include other calendar views as well.

    Will this help you get started? Please let me know. 🙂

    Cheers,
    Geoff

    #1128177
    Glen Draeger
    Participant

    Thanks, but this throws the error:

    Undefined index: eventDisplay

    #1128183
    Glen Draeger
    Participant

    I got it to stop throwing errors by adding this:

    if ( ! isset( $query->query_vars[‘eventDisplay’] ) ) return; (found on your forums)

    Everything is working. Thanks so much. I could not have figured that out on my own.

    #1128388
    Geoff
    Member

    Awesome! Nice work and thanks for following up to let me know that all is working.

    Have a great weekend and let us know if any other questions pop up!

    Cheers,
    Geoff

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Exclude Event Category from Calendar but NOT custom Query’ is closed to new replies.