Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rileypaulsen/6102261 to your computer and use it in GitHub Desktop.
Save rileypaulsen/6102261 to your computer and use it in GitHub Desktop.
get x number of upcoming events from the all in one events calendar
function get_ai1ec_upcoming_events($number = 3){
global $wpdb;
$todaysDate = date('Y-m-d G:i:s');
$upcomingEvents = $wpdb->get_results(
"SELECT
{$wpdb->prefix}posts.post_title,
{$wpdb->prefix}posts.ID,
{$wpdb->prefix}ai1ec_event_instances.start,
{$wpdb->prefix}ai1ec_event_instances.end
FROM
{$wpdb->prefix}posts,
{$wpdb->prefix}ai1ec_event_instances
WHERE
{$wpdb->prefix}posts.post_type='ai1ec_event'
AND {$wpdb->prefix}posts.ID={$wpdb->prefix}ai1ec_event_instances.post_id
AND {$wpdb->prefix}ai1ec_event_instances.start>='$todaysDate'
ORDER BY
{$wpdb->prefix}ai1ec_event_instances.start
ASC
LIMIT $number
"
);
return $upcomingEvents;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment