Problem with tribe_get_events() showing events earlier than its start_date

Home Forums Calendar Products Events Calendar PRO Problem with tribe_get_events() showing events earlier than its start_date

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1025042
    James
    Participant

    Hello all,

    Having a problem with tribe_get_events(). It retrieves an event which starts BEFORE start_date!

    Code:

     <?php 
          global $post;
    				
          $now = new DateTime('2015-11-13 21:05');
          echo $now->format('y-m-d H:i') . '<br>';
    
          $events = tribe_get_events( array(
             'eventDisplay'   => 'upcoming',
             'start_date' => $now->format('y-m-d H:i')
           ) );
    
           foreach ( $events as $post ) {
               setup_postdata( $post );
    
               $event = new DateTime(tribe_get_start_date( null, true, "y-m-d H:i:s"));
               echo $event->format('y-m-d H:i:s');
           } 
    ?>

    This is the output I get:

    15-11-13 21:05
    15-11-13 21:00

    I assign to $now a timestamp that’s AFTER the $event, and pass it to start_date.
    Yet the loop still picks up the $event, and displays it.

    Why is a loop which starts at 21:05 displaying an event which starts at 21:00?

    //

    For eventDisplay I’ve tried custom, upcoming, all. No difference.

    #1025063
    Brook
    Participant

    Howdy James,

    Good question. tribe_get_events() retrieves all events that are ongoing between the two dates. In other words if the events end date is taking place between those dates, perhaps because its end date is inside of or after your date search, then it will show in the list.

    Does that make sense?

    Cheers!

    – Brook

    #1025443
    James
    Participant

    Thanks Brook!

    What would you say is the best way to precisely limit events which the loop picks up? Should I add an end_date which is 5 minutes after start_date?

    In other words going back to my example,

    15-11-13 21:05
    15-11-13 21:00

    How do I run the loop which starts at 21:05, and doesn’t pick up an event starting at 21:00?

    #1026684
    Brook
    Participant

    Howdy James,

    That would actually be so very tricky to do. It’s probably surprising, but that is an extremely rare use case and so we do not have tools for it. You would need to write your own SQL query almost from scratch to get events whose start_date date and presumably end_date are within a date range parameters. I just spent a while digging through our codebase to see if there is anything you could build off of or simplify to do this, and I can not find a thing.

    Obviously such a thing is going to require a decent knowledge of SQL to do. But if you have such knowledge checkout our documentation on The Events Calendar post meta keys. It will give you the keys for everything in the database.

    I hope that helps! I wish I could make this easier. Cheers!

    – Brook

    #1027073
    James
    Participant

    I find it hard to imagine this is a rare use case. Maybe I’m missing something very obvious?

    My only goal is simply to output a list of upcoming events. I take the start_date as strtotime(now), and retrieve everything from that on.

    How can this be a rare use case?

    Can you suggest some easy way you’d implement this usecase without writing heavy SQL? I’ve purchased this plugin to perform this very simple use case.

    #1027112
    Brook
    Participant

    I can see how that would be surprising. But I have actually been on the support team the longest and yet I’ve never seen such a request til now. Because most folks want their upcoming list to include events that are happening now. You can definitely request it as a feature, perhaps more people will come out of the woodworks wanting the same thing: UserVoice (feature suggestion page for The Events Calendar)

    There really is no direct way to do this without writing a decent measure of SQL. 🙁 You can try manually excluding events by moving your start_time to be after they end, but that will not work in scenarios where an ongoing you want to exclude ends after a different event that hasn’t started yet.

    I am very sorry if the plugin is not meeting your needs here. 🙁 Please don’t hesitate to ask for a refund if you are dissatisfied. We process all refunds via email, so send an email to support @ this website if that’s your preferred route.

    Does that clarify everything? Cheers!

    – Brook

    #1027115
    James
    Participant

    Okay so, the most typical use case lists upcoming and current events? If that use case works 100% as expected, then maybe the best case scenario is to talk with our customer and nudge the expectations a bit.

    To solve the use case as I initially outlined, how would I exclude events by moving my start_date after their end? Can this be done without SQL?

    Thank you for all your help!

    #1027290
    Brook
    Participant

    You’re welcome James. I really wish I could be of even more help here, or that it was simpler to modify. I appreciate your understanding.

    Nudging their expectations might make a lot of sense. Often times you want currently ongoing events to be listed for folks that are running late, or especially for longer running events.

    What I meant by nudged the start_date is changing it to something after any currently ongoing event. If your current ongoing event ends at 11pm, then have the start date be 11:05pm. Make sense?

    Cheers!

    – Brook

    #1043897
    James
    Participant

    Thanks Brook I’ve gotten it to work.

    Your explanation that tribe_get_events() presupposes the current event was what I needed. This should be documented somewhere! Saying that it retrieves upcoming events, without that being precisely the case, can be misleading and lead people to believe the plugin isn’t working correctly, when it is.

    Thanks once again!

    #1044461
    Brook
    Participant

    Howdy James. I appreciate the feedback. Perhaps calling it ongoing and upcoming in the docs would clarify.

    Thanks for getting back to us and letting us know you’re all set. Cheers!

    – Brook

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Problem with tribe_get_events() showing events earlier than its start_date’ is closed to new replies.