Home › Forums › Calendar Products › Events Calendar PRO › Using tribe_get_events On Main Calendar Page Recurring Events Issue
- This topic has 10 replies, 4 voices, and was last updated 7 years, 5 months ago by Brook.
-
AuthorPosts
-
October 23, 2016 at 9:49 pm #1181760Glen DraegerParticipant
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.
October 23, 2016 at 9:55 pm #1181761Glen DraegerParticipantJust to clarify the above, when I switch the main calendar to list view, the slider works as it should.
October 24, 2016 at 5:18 pm #1182201ShelbyParticipantHey 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
October 25, 2016 at 9:01 am #1182494Glen DraegerParticipantYes and no. I had to manually get rid of them so that they didn’t all show. It’s the “Ghost Roast” 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.pngIn List view:
http://www.eventsonline.com/hoteldel/2016-10-25_08-57-13.pngIt 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.
October 26, 2016 at 10:40 am #1183310ShelbyParticipantHey 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
October 26, 2016 at 11:32 am #1183332BrookParticipantHowdy 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
October 26, 2016 at 11:58 am #1183343Glen DraegerParticipantThanks 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.
October 27, 2016 at 10:30 pm #1184258BrookParticipantDoh! 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
November 1, 2016 at 7:45 am #1185754Glen DraegerParticipantThanks Brook! That worked perfectly!
Really appreciate you figuring this out.
November 2, 2016 at 10:15 am #1186460BrookParticipantYou are very welcome Glen! Glad to be of help. Thanks for getting back.
– Brook
-
AuthorPosts
- The topic ‘Using tribe_get_events On Main Calendar Page Recurring Events Issue’ is closed to new replies.