Home › Forums › Calendar Products › Events Calendar PRO › tribe_get_events next event by hour
- This topic has 6 replies, 3 voices, and was last updated 7 years, 11 months ago by Support Droid.
-
AuthorPosts
-
April 30, 2016 at 4:00 pm #1109208Malcolm GreenParticipant
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.
May 2, 2016 at 5:13 am #1109431NicoMemberHowdy 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,
NicoMay 2, 2016 at 7:04 am #1109466Malcolm GreenParticipantThanks 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…
May 3, 2016 at 9:46 am #1110112NicoMemberHey 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,
NicoMay 3, 2016 at 12:37 pm #1110181Malcolm GreenParticipantThanks 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….?
May 4, 2016 at 6:42 am #1110410NicoMemberHey 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,
NicoMay 19, 2016 at 9:35 am #1116465Support DroidKeymasterThis 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 ‘tribe_get_events next event by hour’ is closed to new replies.