Hello Stephen,
Can we use [eo_fullcalendar event_start_after=”now”] to only show the events on the calendar starting from today?
Thanks,
David
David Nathan
Or [eo_fullcalendar showpastevents=false]?
David
David Nathan
Hi David,
No, the calendar shortcode doesn’t support those attributes; it allows complete navigation.
Stephen Harris
Hello Stephen,
Thanks for your prompt response.
It would be a great improvement for the user experience if there was a way that past events could be hidden from the calendar view.
Cheers,
David
David Nathan
It would be possible to weed out past events, e.g. by user the eventorganiser_fullcalendar
filter (but the calendar itself would still be navigable to past dates). I’m just not sure I see the benefit in preventing users going back in time.
Stephen Harris
Hello, Stephen,
I do understand that you, as the system architect, wish to give the user unlimited calendar navigation power.
From the user’s perspective, I always think of the first impression the user gets when they see a screen.
My calendar is for tourists on holiday. My default is the monthly view.
Perhaps they arrive in a strange and unfamiliar town during the last week of the month.
Currently, the event calendar “poisons” the start of their holiday experience by showing them 3 weeks of events they have missed… They are quite likely to never visit my site ever again!
It is identical to a shop prominently advertising the Special Offers it has had in the past…
I believe that the only point of having an event calendar is to show future events that people could possibly attend. Showing my users events they cannot possibly attend, because of the arrow of time, may well be programmatically correct, but is nevertheless somewhat callous on my part – as I am the person responsible for the existence of the calendar on my site.
I must however admit that, on rare occasions, an “archive” view (normally disabled), could, with advantage, be enabled under user control.
Just my $0.02
David
David Nathan
Hi David,
Well, you could remove past events from the calendar using the eventorganiser_fullcalendar
filter. For example (I’m using an anonymous function purely for brevity),
add_filter( 'eventorganiser_fullcalendar', function( $events ){
if( $events ){
foreach( $events as $index => $event ){
//$event is an array
//$event['start'] is the start datetime
//formatted as 2014-04-02T16:45:00Z
if( /*event is past*/ ){
unset( $events[$index] );
}
}
}
return $events;
});
There are other ways of achieving this, but each of those involve disabling the cache (which is part of the reason that relative date queries are not supported by the calendar).
In 2.13.0 you’ll also be able to alter the query, but again, unless you disable the cache then it’s probable that your data will become stale.
Stephen Harris
Hi Stephen,
Thank you for your response. I have made some progress based on this.
I am quite ignorant of php, however I managed to put your code in an utility plugin and added a date comparison line to suppress events before today:
// if( /*event is past*/ ){
if( new DateTime($event['start']) < new DateTime('today') ){
unset( $events[$index] );
This had an effect!
April view: all events from 29 March to 2 May are suppressed i.e including all those after today!
May view: all events from 26 April to 6 June are shown.
It looks like there may well be a cache effect, as the events of 26 April to 2 May only show up in the May view.
Is this resolvable?
Thanks,
David
David Nathan
Hi David,
It would appear that the returned array must have a sequential indices.
Try return array_values( $events );
in the above snippet.
Stephen Harris
Hello Stephen,
Thanks for all your help – and your patience with me!
It all works perfectly now!
Here is the final code, for completeness.
add_filter( 'eventorganiser_fullcalendar', function( $events ){
if( $events ){
foreach( $events as $index => $event ){
//$event is an array
//$event['start'] is the start datetime
//formatted as 2014-04-02T16:45:00Z
if( new DateTime($event['start']) < new DateTime('today') ){
unset( $events[$index] );
}
}
}
return array_values( $events );
});
Cheers,
David
David Nathan
P.S. I changed “start” to “end”
David Nathan