Can we use [eo_fullcalendar event_start_after="now"] ?
WordPress Event Management, Calendars & Registration › Forums › Request A Feature › Can we use [eo_fullcalendar event_start_after="now"] ?
This topic contains 10 replies, has 2 voices, and was last updated by David Nathan 10 years, 4 months ago.
-
AuthorPosts
-
April 2, 2015 at 8:00 am #15971
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
April 2, 2015 at 8:10 am #15972Or [eo_fullcalendar showpastevents=false]?
David
David Nathan
April 2, 2015 at 10:38 am #15975Hi David,
No, the calendar shortcode doesn’t support those attributes; it allows complete navigation.
Stephen Harris
April 2, 2015 at 10:57 am #15976Hello 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
April 2, 2015 at 2:35 pm #15980It 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
April 2, 2015 at 4:20 pm #15985Hello, 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
April 2, 2015 at 4:52 pm #15986Hi 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
April 2, 2015 at 9:58 pm #16003Hi 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
April 2, 2015 at 10:11 pm #16004Hi David,
It would appear that the returned array must have a sequential indices.
Try
return array_values( $events );
in the above snippet.Stephen Harris
April 2, 2015 at 10:45 pm #16005Hello 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
April 3, 2015 at 8:48 am #16009P.S. I changed “start” to “end”
David Nathan
-
AuthorPosts
The forum ‘Request A Feature’ is closed to new topics and replies.