Get Start Date of Next Recurring Event

Home Forums Calendar Products Events Calendar PRO Get Start Date of Next Recurring Event

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #28012
    Stephen Chuchel
    Participant

    Inside 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.

    #28202
    Barry
    Member

    For 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?

    #28315
    Barry
    Member

    Hi EMRL – did you sort everything out here/have any further questions?

    #28337
    Stephen Chuchel
    Participant

    Yeah 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.

    #28338
    Barry
    Member

    So 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.

    #28340
    Stephen Chuchel
    Participant

    So you’re saying that tribe_get_events(‘eventDisplay=upcoming&posts_per_page=-1′) isn’t useful in this case?

    #28341
    Stephen Chuchel
    Participant

    Because, I’d expect that to return events after today, that have the correct event date, but they don’t when is_admin() is true.

    #28345
    Barry
    Member

    Right, 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.

    #28349
    Stephen Chuchel
    Participant

    Alright. I just wanted to see if there were another alternative or shortcut within the plugin already. Thanks.

    #28356
    Barry
    Member

    Hmm, 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 🙂

    #28358
    Stephen Chuchel
    Participant

    Yeah, 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.

    #28386
    Barry
    Member

    Nice! Are you all sorted here/do you have any further questions?

    #28462
    Stephen Chuchel
    Participant

    I 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.

    #28465
    Barry
    Member

    Great, 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 🙂

    #978212
    Support Droid
    Keymaster

    This 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.

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Get Start Date of Next Recurring Event’ is closed to new replies.