eo_get_events
since 1.0.0
eo_get_events( $args = array() )
Retrieve list of events matching criteria.
This function is a wrapper for get_posts(). As such parameters from get_posts() and WP_Query
can also be used.
Their default values are as indicated by the relevant codex page unless specified below.
You can also use get_posts() and WP_Query
instead to retrieve events.
The $args
array can include the following.
- 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 before the given date
- event_end_after - default:
null
. Events that end after the given date. This argument, and those above expect dates in Y-m-d format or relative dates.
- ondate - Events that start on this specific date given as a string in YYYY-MM-DD format or relative format. default:
null
- numberposts - default is
-1
(all events)
- orderby - default is
eventstart
. You can also have eventend
.
- showpastevents - default is
true
(it's recommended to use event_start_after=today
or event_end_after=today
instead)
- 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 venue. Get events for this tag
- group_events_by - If set to 'series', only the first matching occurrence of a recurring event is returned.
- 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.
For more complex event/venue queries you can use tax_query or venue_query ( http://wp-event-organiser.com/pro-features/event-venue-queries/ ).
If you use get_posts()
or WP_Query
instead then you should ensure the following:
- post_type - is set to 'event'
- suppress_filters - is set to false
Example
<?php
$events = eo_get_events(array(
'numberposts'=>5,
'event_start_after'=>'today',
'showpastevents'=>true,
));
if($events):
echo '<ul>';
foreach ($events as $event):
$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, $event->occurrence_id )
);
endforeach;
echo '</ul>';
endif;
?>
As previously noted, function uses WordPress' built-in get_posts and all arguments available to get_posts are available to this function. This allows for potentially complex queries.
For instance, to get the next 5 events which aren't in the category with slug 'comedy':
$events = eo_get_events(array(
'numberposts'=>3,
'tax_query'=>array( array(
'taxonomy'=>'event-category',
'operator' => 'NOT IN',
'field'=>'slug',
'terms'=>array('comedy')
))
Parameters
array
|
$args = array() |
Event query arguments.
|
Return value
array
|
An array of event (post) objects. Like get_posts. In case of failure it returns null.
|
Changelog
Resources