WordPress All-In-One Event Calendar: Show Upcoming Events Only

I’m using the All-In-One Event Calendar found here: http://wordpress.org/extend/plugins/all-in-one-event-calendar/
I’m trying to display upcoming events only (so no past events) using the WP_Query() function. I see there is a “wp_ai1ec_events” table in the database and a column named “start” with the start times in yyyy-mm-dd hh:mm:ss format. I can get the current time in the same format using $currentTime = current_time(‘mysql’)

This is what my query looks like so far:

Read More
    $frontpageevents='post_type=ai1ec_event&showposts=3&orderby=start&order=ASC&meta_value=yes';
$eventquery = new WP_Query($frontpageevents);

I’ve tried adding ‘&start>’.$currentTime to the end of the $frontpageevents declaration, but that didn’t work. I was hoping if someone knew how to handle this.

Related posts

Leave a Reply

2 comments

  1. http://wordpress.org/support/topic/plugin-all-in-one-event-calendar-order-event-by-start-date?replies=3#post-2443756

    I’m searching for something similar. I found the above post which should help!

    “Events are posts but event start/end date != post date. When you make a query, you have to do an event query, not post query. In other words, you have to use plugin’s API to retrieve events ordered by start or end dates. The function of interest is get_events_between(). It is located in Ai1ec_Calendar_Helper class. The class is located in: app/helper/class-ai1ec-calendar-helper.php I modified your code a bit. I haven’t tested it so there might be typos or other errors but the logic is the same: http://pastebin.com/SNp4TJij

    Update!

    So I really got this figured out now…Here is the code I set up to get events between today and a year from today.

    
        global $ai1ec_calendar_helper, $ai1ec_events_helper;
    
        // gets localized time
        $bits = $ai1ec_events_helper->gmgetdate( $ai1ec_events_helper->gmt_to_local( 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);
    
        //loop through results to get post_ids
        foreach($get_events as $event ):
            $post_ids[] = $event->post_id;
        endforeach;
    
        // The New Events Query
        $args = array(
            'posts_per_page'  => 4,
            'paged' => get_query_var('paged'),
            'post_type'=> 'ai1ec_event',
            'post__in' => $post_ids
        );
    
        $events_added = new WP_Query( $args );
    
        // The Loop
        while ( $events_added->have_posts() ) : $events_added->the_post();
            $event = Ai1ec_Events_Helper::get_event($post->ID);
            //Your code here
        endwhile;
        wp_reset_postdata();
    

    You can also use the function get_events_relative_to() with args for the start time, a limit for the number of results, page offset(which is used in their views for ai1ec not the same as wp pagination), and filters…it returns a multidimensional array of event objects. I had to create $events = $get_events[‘events’] and use $events in my foreach to properly retrieve the post_ids.

    I looked through the ai1ec-themes to find examples of how to display event data.
    echo apply_filters( 'the_content', $event->post->post_content );
    Returns HTML formated event info like what is shown in a single event page.

  2. The $post_ids array is already in order by start date. In your $args variable add ‘orderby’ => ‘post__in’

     $args = array(
            'posts_per_page'  => 4,
            'paged' => get_query_var('paged'),
            'post_type'=> 'ai1ec_event',
            'post__in' => $post_ids,
            'orderby' => 'post__in'
        );