Using tribe_get_events On Main Calendar Page Recurring Events Issue

Home Forums Calendar Products Events Calendar PRO Using tribe_get_events On Main Calendar Page Recurring Events Issue

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

    On the main calendar page, I have a slider at the top of the page that shows events from a specific category. We have recurring events in that category. Only one of the recurring events should show. This does happen when we switch to list view, but in Month view all the recurring events show in the slider. It appears the main Calendar query is affecting my slider query (which uses tribe_get_events). I’ve tried this to no avail:

    `$events = tribe_get_events( array(
    ‘posts_per_page’ => 20,
    ‘start_date’ => date( ‘Y-m-d H:i:s’ ),
    ‘eventDisplay’ => ‘list’,
    ‘tribeHideRecurrence’ => 1,
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘tribe_events_cat’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘special-events’,
    )
    )
    ) );

    Is there someway to stop the main calendar query from affecting my query for the slider? I’m using WP’s standard wp_reset_postdata()….but this doesn’t seem to help. And I have checked the box “Show only the first instance of each recurring event (only affects list-style views).” in case you’re wondering.

    #1181761
    Glen Draeger
    Participant

    Just to clarify the above, when I switch the main calendar to list view, the slider works as it should.

    #1182201
    Shelby
    Participant

    Hey Glen,

    Welcome back to our forums! I’d love to help you out with this.

    Can you send me a link to the page with the functionality you reference here so I can take a closer look?

    Cheers! 🙂

    Shelby

    #1182494
    Glen Draeger
    Participant

    Yes and no. I had to manually get rid of them so that they didn’t all show. It’s the “Ghost Roast” events:

    http://hoteldel.com/events/

    You can see them all on the individual days in month view.

    See these screenshots from my local server:

    In calendar view:
    http://www.eventsonline.com/hoteldel/2016-10-25_08-55-24.png

    In List view:
    http://www.eventsonline.com/hoteldel/2016-10-25_08-57-13.png

    It looks to me like the main calendar page is affecting my custom query somehow.

    I use the same code in popup slider and it works fine….as long as you are not on the main calendar page. Then it does the same thing…shows all the recurring events.

    #1183310
    Shelby
    Participant

    Hey Glen,

    Wanted to let you know I’m working with some other team members on this one. I’ll hopefully be able to update you shortly, & I appreciate your patience!

     

    Shelby

    #1183332
    Brook
    Participant

    Howdy Glen,

    I would love to help you with this as best as we’re able. We can only provide so much support for customizations like this, but we love to point you in the right direction as best we can.

    I think you will want to unhook the Tribe__Events__Pro__Main:->setup_hide_recurrence_in_query() method from ‘tribe_events_pre_get_posts’, and hook your own custom version back on to that action. Something like this should unhook it:

    remove_action( 'tribe_events_pre_get_posts', array( Tribe__Events__Pro__Main::instance(), 'setup_hide_recurrence_in_query' ) );

    From there I would copy the contents of that method into your own custom function:

    function glens_setup_hide_recurrence_in_query( $query ) {
    
       if ( ! isset( $query->query_vars['is_tribe_widget'] ) || ! $query->query_vars['is_tribe_widget'] ){
          // don't hide any recurrences on the all recurrences view
          if ( tribe_is_showing_all() || tribe_is_week() || tribe_is_month() || tribe_is_day() ) {
             return $query;
          }
       }
    
       // don't hide any recurrences in the admin
       if ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
          return $query;
       }
    
       // don't override an explicitly passed value
       if ( isset( $query->query_vars['tribeHideRecurrence'] ) ) {
          return $query;
       }
    
       // if the admin option is set to hide recurrences, or the user option is set
       if ( Tribe__Events__Pro__Main::instance()->should_hide_recurrence( $query ) ) {
          $query->query_vars['tribeHideRecurrence'] = 1;
       }
    
       return $query;
    }

    And then add that as an action to ‘tribe_events_pre_get_posts’. At this point the behavior should be identical, but now your custom function is that one that decides when to filter the query.You could add an extra condition to this to choose not filter the query at times, such as when a custom query var that you have added is present.

    Does that all make sense to you or your developer?

    Cheers!

    – Brook

    #1183343
    Glen Draeger
    Participant

    Thanks for the attempt, but that still did not work. I tried setting the query var manually in month view…..it still had no effect. See this link:

    http://www.eventsonline.com/hoteldel/2016-10-26_11-49-48.png

    It just seems very odd. The slider does exactly what it is supposed to do on any other page and in any other view on the main calendar page….except Month view.

    #1184258
    Brook
    Participant

    Doh! I looked a bit deeper and I think I understand why this is happening now. Inside of Tribe__Events__Pro__Recurrence__Queries::collapse_sql() it looks like it is double checking if it is month view, and then bailing. Even though the above function has already checked. There are probably some edge cases that this double checking is meant to prevent.

    I have one more idea. Immediately before building and running your query you could tell the Tribe API that it’s not on Month view with something like this:

    add_filter( 'tribe_is_month', '__return_false' );

    Then right after you have run your query undo this:

    remove_filter( 'tribe_is_month', '__return_false' );

    If that does not work we might be out of options. Did that or a similar strategy work?

    Cheers!

    – Brook

    #1185754
    Glen Draeger
    Participant

    Thanks Brook! That worked perfectly!

    Really appreciate you figuring this out.

    #1186460
    Brook
    Participant

    You are very welcome Glen! Glad to be of help. Thanks for getting back.

    – Brook

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Using tribe_get_events On Main Calendar Page Recurring Events Issue’ is closed to new replies.