All-in-One Event Calendar: Custom Query – Getting each event Instance [closed]

Finally have a chance to post my solution. Note that the events show All Day events first if there are any. Unfortunately I don’t know a way around this as it is coded this way in a SQL query within one of the plugin files (and it is even commented in the file that All Day events are first).

I am also using the event information collected into image data attributes as it is for a carousel using Cycle2. But you can just change that part to echo out the information or however you want to format it.

I hope this helps someone else if they come across the need to get events from the AI1EC plugin!

<?php

    // Gets localized time
    $time = $ai1ec_events_helper->gmt_to_local( Ai1ec_Time_Utility::current_time() );
    $bits = $ai1ec_events_helper->gmgetdate( $time );

    // Sets start time to today
    $start = gmmktime(0,0,0,$bits['mon'],$bits['mday'],$bits['year']);

    // Sets end time to a year from today i.e. $bits['year']+1
    $end = gmmktime(0,0,0,$bits['mon'],$bits['mday'],$bits['year']+1);

    // Look in class-ai1ec-calendar-helper.php for details
    $get_events = $ai1ec_calendar_helper->get_events_between($start, $end, $filter, $spanning = false);

    date_default_timezone_set('America/Toronto'); // Match timezone settings in WP

    // For each event
    foreach($get_events as $event) {

        // Event ID
        $eventID = $event->post->ID;

        // Event Title
        $eventTitle = $event->post->post_title;

        // Event URL
        $eventURL = $event->post->guid . $event->instance_id;

        // Event Date
        $eventMonth = date( 'M', $event->start );
        $eventDay = date( 'd', $event->start );

        // Event Image
        $imgID = get_post_thumbnail_id( $eventID );

        // Event Time
        if( $event->allday == 1 ) {
            $timeSpan = 'All Day';
        } else {
            $startTime = date( 'g:ia', $event->start );
            $endTime = date( 'g:ia', $event->end );
            $timeSpan = $startTime . ' - ' . $endTime;
        }

        $attr = array(
            'alt' => get_post_meta( $imgID , '_wp_attachment_image_alt', true ), 
            'data-name' => $eventTitle, 
            'data-month' => $eventMonth,
            'data-day' => $eventDay,
            'data-time' => $timeSpan,
            'data-url' => $eventURL
        );
        echo get_the_post_thumbnail( $eventID, 'full', $attr );
    }
?>

Leave a Comment

error code: 523