Support

Home Forums Events Calendar Add-on Month and Year override for calendar

Month and Year override for calendar

Posted: September 12, 2017 at 6:46 pm


Amanda Brackett

September 12, 2017 at 6:46 pm

Hi everyone! I have a site that uses the Event calendar plugin. The home page has a preview of each month’s events, then a link to the calendar to show all events for that month. To get the calendar to display a particular month, I use the override parameters in the URL:

http://staging.dariendca.org/event-calendar/?year=2017&month=12

Which, for example, shows decemeber 2017, which is great. The problem is, once I change the year to 2018, it breaks and can’t show it:

http://staging.dariendca.org/event-calendar/?year=2018&month=01

Is there something I’m doing wrong?

Thanks


Tony

  • Support Staff

September 13, 2017 at 4:33 am

Hi there,

The year query var is actually being used by WordPress so when you do the above your actually telling the main WP query to look for a post for that specific year.

So in your example this /event-calendar/?year=2017&month=12 tells WordPress to look for a WP post ‘event-calendar’ with a post date in 2017 (it finds your calendar post and shows that).

This /event-calendar/?year=2018&month=12 tells WP to looks for a WP post with post date in 2018, so it finds nothing as your calendar post was created in 2017.

Month isn’t used by WP so then EE picks that up from the request and uses it with the calendar.

Those query vars are available for the ajax requests rather than to be included within query string for the page. Did you find documentation recommending you use those somewhere?


Amanda Brackett

September 13, 2017 at 3:40 pm

Gotcha, thanks for your reply! I didn’t see them in documentation, but I combed through the code and found them referenced as override strings:

$overrides = array(
                    'event_category_id' => isset($_REQUEST['event_category_id'])
                            ? sanitize_key($_REQUEST['event_category_id'])
                            : $js_option_event_category_id,
                    'event_venue_id'    => isset($_REQUEST['event_venue_id'])
                            ? sanitize_key($_REQUEST['event_venue_id'])
                            : $js_option_event_venue_id,
                    'month'             => isset($_REQUEST['month'])
                            ? sanitize_text_field($_REQUEST['month'])
                            : $ee_calendar_js_options['month'],
                    'year'              => isset($_REQUEST['year'])
                            ? sanitize_text_field($_REQUEST['year'])
                            : $ee_calendar_js_options['year'],
            );

Since I need to create the links as standalone rather than going through AJAX requests is there a way to do this? I guess my question is, is there a way to make a link that will load a calendar for a specific month and year (without manually creating a page for every month and year with different shortcakes embedded)

Thanks!


Josh

  • Support Staff

September 14, 2017 at 2:50 pm

Hi there,

Your links like this one:
(http://staging.dariendca.org/event-calendar/?year=2018&month=01)
should work OK if you can remove the year part from the WP Query. Here’s an example you can add to a site specific custom functions plugin:

add_filter( 'request', 'my_custom_remove_year_query_arg' );
function my_custom_remove_year_query_arg( $request ) {
  if( 
    isset($request['pagename']) && 
    $request['pagename'] == 'event-calendar' 
  ) { 
      unset($request['year']);
  }
  return $request;
}

You can add the above to a functions plugin, then activate the plugin.

The support post ‘Month and Year override for calendar’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso