eo_get_current_occurrence_of

This topic contains 3 replies, has 2 voices, and was last updated by  Stephen Harris 10 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #7364

    Hey Stephen,

    Can you please tell me what I’m doing wrong here, or maybe give a quick example how to use this.

    I’m trying to use eo_get_current_occurrence_of on a single event page to show the current date/time of a recurring event…

    I tried this:

    <?php
    $occur = eo_get_current_occurrence_of();
    echo $occur['start'];
    ?>
    

    The problem is nothing’s showing up… What gives?

    Thanks for the help!

    pach16
    #7384

    Hi pach16, the returned ‘start’ and’end’ values are DateTime objects, so you’ll need to do something like:

    $start = $occur['start'];
    echo $start->format('jS F Y');
    

    Please note that the function returns false if an occurrence isn’t currently running.

    Stephen Harris
    #7389

    Thanks,

    Gave that a go, and got error: Fatal error: Call to a member function format() on a non-object in…

    pach16
    #7399

    That’ll be because the function is returning false. You’ll need to make sure 1. An occurrence is actually currently running (occurrence start date occurs before now, and ends in the future) and 2. You are calling this from within in the loop (in the event single page this will generally be after the_post() has been called. Otherwise you’ll need to specify the event ID.

    <?php
    //Inside the loop:
    if( $occur = eo_get_current_occurrence_of() ){
          echo 'This event is now running, it will finish at ' . $occur['end']->format('F, d Y g:ia');
     }else[
          echo 'This event is not currently running';
    }
    ?>
    
    Stephen Harris
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.