Events are ‘post types’ of type ‘event’. This means you can use the usual
get_posts() to query events. There are two things to remember when using them:
- You must set
- When using
get_posts()you must set
You can also use
eo_get_events(). This function is identical to
get_posts() – and both accept the same arguments as
WP_Query. In short you can use any one of those three methods and they all accept the ‘usual’ parameters, as well additional event-specific queries listed below.
eo_get_events() uses different default values (detailed here) and is the recommended method to use. Additional parametres include:
Date query arguments (except
showpastevents) expect dates in Y-m-d format (e.g.
2013-12-24 ) or relative date format
- event_start_before – default:
nullEvents that start before the given date
- event_end_before – default:
nullEvents that end before the given date
- event_start_after – default:
nullEvents that start after the given date
- event_end_after – default:
null. Events that end after the given date.
ondate – Events that start on this specific date
showpastevents – default is
true(it’s recommended to use
Category / Tag / Venue queries
- event-category – the slug of an event category. Get events for this category
- event-venue – the slug of an event venue. Get events for this venue
- event-tag – the slug of an event tag. Get events for this tag
- venue_query – get events with venues matching this venue query (see Querying Venues and Getting Events via Venue Queries).
- bookee_id – (int) ID of user to retrieve events for which the user is attending
Additional values are also permitted for ‘orderby’ parameter
- eventstart – Order by event start date.
- eventend – Order by event end date.
- proxmity – Order by proximity to a given point (requires a
venue_query, see Querying Venues and Getting Events via Venue Queries)
<?php $events = eo_get_events(array( 'numberposts'=>5, 'event_start_after'=>'today', 'showpastevents'=>true,//Will be deprecated, but set it to true to play it safe. )); if($events): echo '<ul>'; foreach ($events as $event): //Check if all day, set format accordingly $format = ( eo_is_all_day($event->ID) ? get_option('date_format') : get_option('date_format').' '.get_option('time_format') ); printf( '<li><a href="%s"> %s </a> on %s </li>', get_permalink($event->ID), get_the_title($event->ID), eo_get_the_start($format, $event->ID,null,$event->occurrence_id) ); endforeach; echo '</ul>'; endif; ?>