Home › Forums › Calendar Products › Events Calendar PRO › Get Start Date of Next Recurring Event
- This topic has 14 replies, 3 voices, and was last updated 10 years, 9 months ago by
Support Droid.
-
AuthorPosts
-
November 13, 2012 at 12:36 pm #28012
Stephen Chuchel
ParticipantInside a WordPress scheduled function (wp_schedule_event) I’m trying to get all upcoming events. So I use tribe_get_events(‘eventDisplay=upcoming&posts_per_page=-1’).
For testing/debugging, I’m inside the WP admin area (I’m not sure what environment scheduled functions run under?) so the normal filters and hooks that Tribe applies to the query aren’t being applied since is_admin is now true.
I can get the _EventStartDate meta from the database (or tribe_get_start_date), but that returns a different date than what $post->EventStartDate would return on the frontend of the website. So is there some way to get the date for the next upcoming event for a recurring event?
Thanks.
November 16, 2012 at 4:20 pm #28202Barry
MemberFor recurring events there will be more than one _EventStartDate entry in the post meta table – so you would need to bear that in mind. Does that help at all?
November 20, 2012 at 9:59 pm #28315Barry
MemberHi EMRL – did you sort everything out here/have any further questions?
November 21, 2012 at 10:04 am #28337Stephen Chuchel
ParticipantYeah sorry, I didn’t notice multiple _EventStartDate entries. But what I noticed is that when I grab all the meta, there is only one _EventStartDate which is different than both the post_date, and the EventStartDate property that is returned with event post objects on the frontend of the website. So I’m not sure where the conversion is happening to get the next recurring date is? I ended up copying the tribe query filter setup function into my own class to be used on the backend, so that EventStartDate would be returned with the post object.
November 21, 2012 at 10:15 am #28338Barry
MemberSo to go back to your original question:
So is there some way to get the date for the next upcoming event for a recurring event?
If you know today is 2012-11-21 then you could essentially just look for posts where the _EventStartDate post meta is greater than that, obtain the post ID and you’d have your event.
November 21, 2012 at 10:23 am #28340Stephen Chuchel
ParticipantSo you’re saying that tribe_get_events(‘eventDisplay=upcoming&posts_per_page=-1′) isn’t useful in this case?
November 21, 2012 at 10:24 am #28341Stephen Chuchel
ParticipantBecause, I’d expect that to return events after today, that have the correct event date, but they don’t when is_admin() is true.
November 21, 2012 at 10:53 am #28345Barry
MemberRight, but as I think you point out yourself this isn’t going to happen since the logic within TribeEventsQuery::setupQuery() is such that the query filters needed for this aren’t put in place (when is_admin() returns true).
Whether that’s true when a scheduled task runs I don’t know, I suspect not but you would need to test that out for yourself – you’ll then be in a position either to use tribe_get_events() or to find an alternative approach whether that’s based on custom queries or an amalgam of WordPress API functions.
November 21, 2012 at 11:22 am #28349Stephen Chuchel
ParticipantAlright. I just wanted to see if there were another alternative or shortcut within the plugin already. Thanks.
November 21, 2012 at 1:51 pm #28356Barry
MemberHmm, nothing springs to mind. Perhaps you could subclass TribeEventsQuery and override the setupQuery() method, eliminating the is_admin() check. Of course that may be a moot point in the context of scheduled tasks anyway.
Be great to hear how you get on and how you solve this 🙂
November 21, 2012 at 2:11 pm #28358Stephen Chuchel
ParticipantYeah, the context is probably just public, because scheduled tasks run when visitors come to your site. But just to be safe, and for testing purposes I added this line:
if ( ! has_action('parse_query', array('TribeEventsQuery', 'setupQuery')))
{
add_action('parse_query', array($this, 'tribe_setup_query'), 0);
}
Which basically copies the setupQuery function without the is_admin() or any other checks.November 23, 2012 at 6:19 am #28386Barry
MemberNice! Are you all sorted here/do you have any further questions?
November 26, 2012 at 10:16 am #28462Stephen Chuchel
ParticipantI guess so.. On another not, it’d be super handy if once you logged in here to post a reply it would redirect you back to the thread you were viewing.
November 26, 2012 at 10:31 am #28465Barry
MemberGreat, I’ll close this thread then.
It’d be super handy if once you logged in here to post a reply it would redirect you back to the thread you were viewing.
Definitely; it’s a point that’s been raised before. There are some changes in the works though and hopefully they’ll be rolled out soon 🙂
July 7, 2015 at 6:26 am #978212Support Droid
KeymasterThis 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. -
AuthorPosts
- The topic ‘Get Start Date of Next Recurring Event’ is closed to new replies.
