eo_get_the_start() how to get occurrence id outside the event page?

WordPress Event Management, Calendars & Registration Forums General Question eo_get_the_start() how to get occurrence id outside the event page?

This topic contains 2 replies, has 2 voices, and was last updated by  Adrian Maleska 10 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10138

    I’m using this function to calculate the event duration in days and display it above the booking form.

                  $curr_start_date  =   eo_get_the_start('Ymd', $event_id); 
                  $curr_end_date    =   eo_get_the_end('Ymd', $event_id);       
    
                  $event_duration_days = ($curr_end_date - $curr_start_date) +1;
                  $days_suffix = $event_duration_days > 1 ? "Days" : "Day";
    
                  echo "Event length is "."event_duration_days." ".$days_suffix;

    On the event page everything works fine but I’m also using the booking form via shortcut in posts and there eo_get_the_start(‘Ymd’, $event_id); returns false.

    I’m aware that this may be related to this post:
    eo_get_the_start-not-working-anymore-on-update

    Obviously I should feed the fourth argument with the occurrence id like that:

          eo_get_the_start('Ymd', $event_id, null,$post->occurrence_id);

    But I’m on an other page and $post->occurrence_id will deliver nothing. Now I’m stucked. Any idea how to get the occurrence id?

    Adrian Maleska
    #10147

    Since all occurrences of an event have to be the same length you can simply pick one. You can get an array of occurrence IDs for an event by following this thread: http://wp-event-organiser.com/forums/topic/get-occurrence-id/. To get one occurrence ID, just use array_pop or array_shift. (for the last / first ID).

    Stephen Harris
    #10157

    Oh I see, now it’s clear to me. I made a function out of it for later usage:

    echo "Next occurrence_id is: ".get_closest_occurrence_id($this_event_id);
    
    function get_closest_occurrence_id($event_id)
    {
            $occurrences = eo_get_the_occurrences_of( $event_id );
            if($occurrences)
            {
                $occurence_ids = array_keys( $occurrences );
                return $occurence_ids[0];
            }
            else
                return null;
    }

    Thanks a lot Stephen!

    Adrian Maleska
Viewing 3 posts - 1 through 3 (of 3 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.