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 9 years, 8 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #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
    #15972

    Or [eo_fullcalendar showpastevents=false]?

    David

    David Nathan
    #15975

    Hi David,

    No, the calendar shortcode doesn’t support those attributes; it allows complete navigation.

    Stephen Harris
    #15976

    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
    #15980

    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
    #15985

    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
    #15986

    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
    #16003

    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
    #16004

    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
    #16005

    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
    #16009

    P.S. I changed “start” to “end”

    David Nathan
Viewing 11 posts - 1 through 11 (of 11 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.