Using tribe_event_is_on_date() even more conditionally

Home Forums Calendar Products Events Calendar PRO Using tribe_event_is_on_date() even more conditionally

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1193280
    RANDY
    Participant

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

    #1193797
    Josh
    Participant

    Hey 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!

    #1193825
    RANDY
    Participant

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

    #1194428
    Josh
    Participant

    Hey 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!

    #1194476
    RANDY
    Participant

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

    #1195285
    Josh
    Participant

    Hey 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!

    #1195310
    RANDY
    Participant

    Josh,

    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.

    #1195748
    Josh
    Participant

    Hey 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!

    #1195775
    RANDY
    Participant

    Josh,

    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?

    #1196715
    Josh
    Participant

    Hey 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!

    #1206472
    Support Droid
    Keymaster

    Hey 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

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Using tribe_event_is_on_date() even more conditionally’ is closed to new replies.