Events are ‘post types’ of type ‘event’. This means you can use the usual WP_Query
or get_posts()
to query events. There are two things to remember when using them:
- You must set
post_type
toevent
. - When using
get_posts()
you must setsuppress_filters
tofalse
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 queries
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:
null
Events that start before the given date - event_end_before – default:
null
Events that end before the given date - event_start_after – default:
null
Events 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 useevent_start_after=today
orevent_end_after=today
instead)
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 queries
- bookee_id – (int) ID of user to retrieve events for which the user is attending
Ordering events
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)
Example
<?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;
?>