Exclude category from events page and paginated pages

Home Forums Calendar Products Events Calendar PRO Exclude category from events page and paginated pages

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1347702
    Lauren Tresp
    Participant

    Hello!

    We are using the following code in our functions.php file to exclude the “ongoing” category from our events page. However, when the events page is paginated, that category is displaying on subsequent paginated pages (so when we click “page 2”, that category shows up in the event feed). Do you know if there is a way to resolve this? Any help is greatly appreciated!

    add_action( ‘pre_get_posts’, ‘tribe_exclude_events_category_month_list’ );
    function tribe_exclude_events_category_month_list( $query ) {

    if ( isset( $query->query_vars[‘eventDisplay’] ) && ! is_singular( ‘tribe_events’ ) ) {

    if ( $query->query_vars[‘eventDisplay’] == ‘photo’ && ! is_tax( Tribe__Events__Main::TAXONOMY ) || $query->query_vars[‘eventDisplay’] == ‘month’ && $query->query_vars[‘post_type’] == Tribe__Events__Main::POSTTYPE && ! is_tax( Tribe__Events__Main::TAXONOMY ) && empty( $query->query_vars[‘suppress_filters’] ) ) {

    $query->set( ‘tax_query’, array(

    array(
    ‘taxonomy’ => Tribe__Events__Main::TAXONOMY,
    ‘field’ => ‘slug’,
    ‘terms’ => array( ‘Ongoing’ ),
    ‘operator’ => ‘NOT IN’
    )
    ) );
    }

    }

    return $query;
    }

    #1348322
    Barry
    Member

    Hi there, Lauren!

    I’m happy to take a look at this – but I should also point out that we are pretty limited in terms of how much support we can offer for custom code.

    The snippet you shared seems like it would work, though, and on testing it out I didn’t have any problems. If I have an event this month in category “Ongoing” and an event next month in that same category, both are removed from month view when the snippet is in place.

    If you aren’t finding the same thing, I wonder if perhaps you happen to have month view caching in place (you can find this option in the Events ‣ Settings ‣ Display tab) … sometimes when you are building customizations for month view it’s best to disable this, at least initially.

    #1352993
    Lauren Tresp
    Participant

    Thank you for the input! We actually ended up disabling month view and are only using the photo view now. So the issue isn’t switching to a new month, the issue is when the user paginates to the next page of events. We have 42 events displayed in photo view, and when you paginate to see the other events all categories are displayed. So page 1 has all events except “ongoing”, while page 2 displays all events including “ongoing”. Do you have any guidance on how we might remove “ongoing” events on all pages in the main event loop? https://themagsantafe.com/events/?action=tribe_photo&tribe_paged=2&tribe_event_display=photo

    #1355253
    Barry
    Member

    Ah, I see (and sorry for the delayed response!).

    Internally, when pagination happens by ajax, the query is either of the type ‘list’ or ‘past’ but not ‘photo’.

    In other words, testing to see if the eventDisplay variable is ‘photo’ will only work on a direct load and not following pagination where the view reloads using an ajax update process.

    Catching this scenario at present would require you test to see if it is an ajax request and by inspecting the action key within the $_POST superglobal (if you need to lock things down to photo view).

    #1365442
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Exclude category from events page and paginated pages’ is closed to new replies.