Home › Forums › Calendar Products › Events Calendar PRO › Using tribe_event_is_on_date() even more conditionally
- This topic has 11 replies, 4 voices, and was last updated 9 years, 4 months ago by
RANDY.
-
AuthorPosts
-
November 16, 2016 at 9:07 am #1193280
RANDY
ParticipantHi there,
I have this working properly: tribe_event_is_on_date()
It works great. The issue is that our events are time sensitive. So we have parts of the event page that are suppose to go online at a certain time and then hide itself after the time has passed.
I was wondering if we can get it down to very time it starts and ends?
November 17, 2016 at 5:53 am #1193797Josh
ParticipantHey Randy,
Thanks for reaching out to us!
Sure thing, you can get a little more granular there, however the simplest way to approach something like that would probably be to use a modified query using “pre_get_posts()” to limit what’s pulled based on time and date.
Would you mind giving a little more detail about what you’re trying to accomplish along with the current code snippet to see if I can help give you a more detailed response and snippet to help you get pointed in the right direction here.
Thanks!
November 17, 2016 at 7:19 am #1193825RANDY
ParticipantHi Josh,
Sure thing!
Here is my code snippet:
<?php if(tribe_event_is_on_date() == true){ echo '<div class="col-xs-12">'; echo '<div class="row">'; echo '<div class="col-xs-12 col-md-8 col-lg-8 youtube-live">'; echo '<iframe width="100%" height="100%" src="https://www.youtube.com/embed/'; $youtubecode = tribe_get_custom_fields(); echo $youtubecode[ 'Youtube Code' ]; echo '" frameborder="0" allowfullscreen></iframe>'; echo '</div>'; echo '<div class="col-xs-12 col-md-4 col-lg-4 youtube-live-chat">'; echo '<iframe width="100%" height="100%" frameborder="1" src="https://www.youtube.com/live_chat?v='; $youtubecode = tribe_get_custom_fields(); echo $youtubecode[ 'Youtube Code' ]; echo '&embed_domain=www.provideocoalition.com"></iframe>'; echo '</div>'; echo '</div>'; echo '</div>'; } ?>So this piece of code is suppose to pop up a Youtube video when we are streaming an event. However, we only want it to appear at the start time of the event and then disappear at the end time of the event.
November 18, 2016 at 6:33 am #1194428Josh
ParticipantHey Randy,
Thanks for following up here!
You can try something like the following as an additional conditional layer:
$date = date( 'U' ); $start = tribe_get_start_date( get_the_ID(), true, 'U' ); $end = tribe_get_end_date( get_the_ID(), true, 'U' ); if ( $date > $start && $date < $end ) { }Let me know if this helps.
Thanks!
November 18, 2016 at 8:26 am #1194476RANDY
ParticipantHi Josh,
This is show it should be formatted correct?
<?php $date = date( 'U' ); $start = tribe_get_start_date( get_the_ID(), true, 'U' ); $end = tribe_get_end_date( get_the_ID(), true, 'U' ); if ( $date > $start && $date < $end ) { echo '<div class="col-xs-12">'; echo '<div class="row">'; echo '<div class="col-xs-12 col-md-8 col-lg-8 youtube-live">'; echo '<iframe width="100%" height="100%" src="https://www.youtube.com/embed/'; $youtubecode = tribe_get_custom_fields(); echo $youtubecode[ 'Youtube Code' ]; echo '" frameborder="0" allowfullscreen></iframe>'; echo '</div>'; echo '<div class="col-xs-12 col-md-4 col-lg-4 youtube-live-chat">'; echo '<iframe width="100%" height="100%" frameborder="1" src="https://www.youtube.com/live_chat?v='; $youtubecode = tribe_get_custom_fields(); echo $youtubecode[ 'Youtube Code' ]; echo '&embed_domain=www.provideocoalition.com"></iframe>'; echo '</div>'; echo '</div>'; echo '</div>'; } ?>If so, it didn’t work unfortunately.
November 21, 2016 at 6:55 am #1195285Josh
ParticipantHey Randy,
Underneath the variable declaration there, can you try running “var_dump($date);” etc. for each of those variables there? Want to make sure that where they’re being used that the appropriate ID is getting passed and real values are getting saved to those variables.
Thanks!
November 21, 2016 at 7:36 am #1195310RANDY
ParticipantJosh,
string(10) “1479742196” is spit out from the dump.
You know, something weird about it. So here’s what happens.
This code only works when the initial event is created for the day (8AM – 5PM). So it spits out the YouTube player and everything, which is correct. However, once I go back and edit the event time to a smaller window (8AM – 3:30PM) it will stop spitting out the YouTube player. But, if I go to let’s say 8AM to 11PM, it will spit out the YouTube player again.
November 22, 2016 at 6:37 am #1195748Josh
ParticipantHey Randay,
Are you managing events across multiple timezonesĀ on your site now? If not, you could add the following above the variable declarations:
date_default_timezone_set( 'America/New_York' );And replace the timezone there with the appropriate timezone for your events. This will help to make sure that the the “date()” that we’re getting will be in the same timezone as the start and end dates set for your events.
Let me know if this helps.
Thanks!
November 22, 2016 at 7:22 am #1195775RANDY
ParticipantJosh,
We did it! It is working as it should now!
For the option in the admin backend, I noticed there was a Timezone mode set to “Use the local timezones for each event”. Should I change this?
November 23, 2016 at 1:06 pm #1196715Josh
ParticipantHey Randy,
That option would just use your WordPress timezone globally for all events created on your site rather than the timezone option set for each event. This can be convenient if all the events on your site are in the same timezone, however it wouldn’t impact the issue we are resolving with the global timezone we’re setting in the code there.
Let me know if this helps.
Thanks!
December 15, 2016 at 8:35 am #1206472Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Using tribe_event_is_on_date() even more conditionally’ is closed to new replies.
