Hi there,
I am new to this plugin but it looks great.
I just have a question about filtering the posts by year and month. Here is what I need:
View All
2013
January
February
March etc…
The months are only shown if there are events starting in that month. What I want is for the user to click on the month e.g. February and all events to show for that month only. Just like you can do to filter posts by category in the normal wordpress posts.
Any help would be great.
zebedeee
This is entirely possible, but I think would require a custom template.
You can use eo_get_events()
(see docs – or WP_Query
with the appropriate attributes set) to retrieve events. Specifically you can use event_start_after
/event_start_before
to get events starting within two dates. E.g.:
//Events for January 2013:
$events = eo_get_events(array(
'event_start_after'=>'2013-01-01',
'event_start_before'=>'2013-01-31',
));
If there are any you can display a link to your page (appending a query variable e.g. ?event-month=01
. That page template can perform a query for the received month (e.g. $month = (int) $_GET['event-month']
and then using that in something like the above, e.g.:
function zebedeee_get_events_for_month( $m, $y ){
$first_day_of_month = new DateTime( $y.'-'.$m.'-01' );
$last_day_of_month = new DateTime( $first_day_of_month->format('Y-m-t') );
//Events for this month
return eo_get_events(array(
'event_start_after'=>$first_day_of_month,
'event_start_before'=>$last_day_of_month,
));
}
/* Usage
$events = zebedeee_get_events_for_month(2013,01);
*/
Stephen Harris
Incidentally,
The following
function zebedeee_register_query_vars( $qvars ){
//Add these query variables
$qvars[] = 'event_start_after';
$qvars[] = 'event_start_before';
return $qvars;
}
add_filter('query_vars', 'zebedeee_register_query_vars' );
Will mean you can use ?event_start_after
and ?event_start_before
in the url (i.e. of the events archive – typically www.yoursite.com/events/event
):
E.g.
www.yoursite.com/events/event?event_start_after=2013-03-01&event_start_before=2013-03-31
will then show events for March 2013. You could then add rewrite rules to make it ‘pretty’.
Stephen Harris