tribe_get_events next event by hour

Home Forums Calendar Products Events Calendar PRO tribe_get_events next event by hour

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1109208
    Malcolm Green
    Participant

    I am trying to set up the code to display the next event by hour but it only seems to grab the event for the day.


    // Retrieve the next event or meal
    $specials = tribe_get_events( array(
    'posts_per_page' => 1,
    'tax_query'=> array(
    array(
    'taxonomy' => 'tribe_events_cat',
    'field' => 'slug',
    'terms' => 'cafe-day'
    )),
    'start_date' => current_time( 'Y-m-d g:i' ),
    'eventDisplay' => 'custom',

    ) );

    As evidenced when I include

    echo tribe_get_start_date();

    How can I return the very next event by time specifically. In my case, I am trying to establish a Breakfast, Lunch and Dinner feature that can happen all on the same day…but the only one returned is Breakfast.

    #1109431
    Nico
    Member

    Howdy Malcolm,

    Welcome to our support forums and thanks for reaching out to us. I’ll help you here…

    In order to help you getting this script ready, I would like to know how are your events set up. Can you give me an example of the start / end dates of your events? Also please note exected result vs the result you are getting now.

    From what you describe I understand that your code is always returning ‘Breakfast’ even if the event has passed and the ‘Lunch’ event is ongoing?

    Please let me know about it so I can help you out,
    Nico

    #1109466
    Malcolm Green
    Participant

    Thanks Nico,

    That’s correct. I have set up three meals (Breakfast, Lunch and Dinner). Breakfast runs from 7-11am. Lunch from 11:05 am to 3pm and Dinner from 3:05pm until 8pm. These are all recurring events.

    I am trying to get the specific mealtime event to return based not only on the day but the hour as well. The only one that seems to return is Breakfast.

    Not sure why it shouldn’t change based on the time?

    Please advise…

    #1110112
    Nico
    Member

    Hey Malcolm,

    Thanks for following up!

    I gave the code a try, just changed the eventDisplay to upcoming (as it made more sense) and the code seems to be working for me. The snippet below will output the next upcoming event before the events template (you can see this in the list view for example) in the front-end:


    function get_next_event ( ){
    // Retrieve the next event or meal
    $specials = tribe_get_events( array(
    'posts_per_page' => 1,
    'tax_query'=> array(
    array(
    'taxonomy' => 'tribe_events_cat',
    'field' => 'slug',
    'terms' => 'mole'
    )),
    'start_date' => current_time( 'Y-m-d g:i' ),
    'eventDisplay' => 'upcoming',

    ) );

    print_r($specials);
    }

    add_action ( 'tribe_events_before_template', 'get_next_event');

    If you are checking the events start time / end time be sure to check the site timezone is the same as your ๐Ÿ˜‰

    Please let me know if this works for you,
    Best,
    Nico

    #1110181
    Malcolm Green
    Participant

    Thanks Nico,

    using ‘upcoming’ for eventDisplay didn’t work (tried that a long time ago). Further, I don’t have this code in my functions, it’s right in the template for the homepage (is there a problem with that?).

    I can verify the timezones are correct and coordinated.

    Simply stumped as to why this doesn’t return anything other than the Breakfast no matter the time of day.

    For development purposes, I’ve even added this code to return the date and time and the ‘next’ event start and end time and it still shows breakfast timings (even when they are now in the past?!).

    
     echo '<br />Current time ';
     echo date( 'Y-m-d g:i' );
     echo '<br />next event - ';
     echo tribe_get_start_date();
     echo ' to ';
     echo tribe_get_end_date();

    Suggestions….?

    #1110410
    Nico
    Member

    Hey Malcolm,

    Thanks for following up!

    itโ€™s right in the template for the homepage (is there a problem with that?)

    Possibly. Maybe there’s a global affecting the query but I’m not sure about it. Can you try to use the code I sent instead (just for testing if it works), and let me know about it?

    Best,
    Nico

    #1116465
    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 7 posts - 1 through 7 (of 7 total)
  • The topic ‘tribe_get_events next event by hour’ is closed to new replies.