Title: yearly filter events using menu ?
Last modified: August 20, 2016

---

# yearly filter events using menu ?

 *  Resolved [glenndm](https://wordpress.org/support/users/glenndm/)
 * (@glenndm)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/)
 * Hi,
    I would like to split the eventscalendar up by year using (sub)menus. As
   2012 was the first year I used events organiser, this hasn’t come up yet.
 * I made a specific page template for showing the events at [http://www.kartcross.be](http://www.kartcross.be).
 * Now I am trying to use submenus to the Kalender menu – using the wordpress menu
   system, one submenu per year.
    Only events pertaining to that year are to be 
   shown.
 * As the modification to the page template is very limited, I’d like to reuse the
   same template by adding the year parameter. All events carry a year category.
 *     ```
       <!-- Event list -->
       	<?php $events = eo_get_events(array('event-category'=>'<YEAR>' )); ?>
       	<?php if($events):
       ```
   
 * The question: How can I pass that year parameter to the template?
 * A submenu has a title attribute which could be used, but I have not yet found
   a way to get to it from the template
 * [http://wordpress.org/extend/plugins/event-organiser/](http://wordpress.org/extend/plugins/event-organiser/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Stephen Harris](https://wordpress.org/support/users/stephenh1988/)
 * (@stephenh1988)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226420)
 * I wouldn’t use categories – you can do date based queries already (to get events
   that start in a given year):
 *     ```
       $year = 2012; //Set the year - we'll discuss this in a minute
         $events = eo_get_events(array(
             'event_start_after' = > $year.'-01-01', //Events after 1st Jan of $year,
             'event_start_before' = > $year.'-12-31', //Events before 31st Dec of $year,
          ));
       ```
   
 * Next to get the year. One way is to use a basic `$_GET`. The idea is that visiting
 * `www.example.com/events/event?event-year=2012`
 * Then
 * `$year = $_GET['event-year'];//E.g. will hold 2012`
 * This doesn’t always work. You may find [this answer on WPSE](http://wordpress.stackexchange.com/questions/46108/wordpress-and-get-params/46111#46111)
   helpful about how to set up a custom query variable (in this example `event-year`).
 * While we’re at it – if this is for the _main query_ then a much better way is:
 *     ```
       add_action('pre_get_posts','my_events_by_year',15);
       function my_events_by_year( $query ){
           if( $query->is_main_query() && is_post_type_archive('event') ){
                if( isset($_GET['event-year']) ){
                   $year = $_GET['event-year'];
   
                   //Events after 1st Jan of $year,
                   $query->set('event_start_after', $year.'-01-01');
   
                   //Events before 31st Dec of $year,
                   $query->set('event_start_before',$year.'-12-31');
                 }
           }
       }
       ```
   
 * Of course the above can be improved by registering the query variable and using`
   get_query_var()` to retrieve the value (the year).
 * _Code not tested, but should work in principle._
 *  Thread Starter [glenndm](https://wordpress.org/support/users/glenndm/)
 * (@glenndm)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226425)
 * Hello Stephen
    My thanks for your extensive reply I’ll try it asap
 * glenn
 *  Thread Starter [glenndm](https://wordpress.org/support/users/glenndm/)
 * (@glenndm)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226441)
 * Hi Stephen,
    Just an update: I finally got the split events working.
 * I struggled with the custom parameter; representing less than 10 lines of code
   and abundantly documented on the web.
    I couldn’t get it to work. Finally I tried
   with a blank WP site; it worked immediately ?!
 * Back to the main site, copying the relevant code verbatim – it fails!
 * At the very last, I discovered the problem:
    **The events page was set as the
   static front page of the wp-site.**
 * Internally this shortens the url of the events page to [http://www.example.com](http://www.example.com)
   instead of [http://www.example.com/events](http://www.example.com/events)
    Also
   this resulted in the default post template being shown instead of the events 
   template. I tried every rewrite rule I could think of, without success.
 * Too much of a (tired) WP newbie, I gave in (for now), setting “Front page Displays
   = your latest posts”
 * The test site works as intended (but for showing the events as start page).
    
   I now only have to modify the live site accordingly (hopefully).
 * Thanks for your help
    glenn
 *  [nisamp17](https://wordpress.org/support/users/nisamp17/)
 * (@nisamp17)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226462)
 * hi glenndm
 * can u pls mail me the entire code for me if you solved the problem.. am also 
   facing the same problem.. send me to this id pls.. [nisamp17@gmail.com](https://wordpress.org/support/topic/yearly-filter-events-using-menu/nisamp17@gmail.com?output_format=md)
 * hopefully
    Nisam
 *  [Stephen Harris](https://wordpress.org/support/users/stephenh1988/)
 * (@stephenh1988)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226463)
 * Actually year, month and day archives will be available in 1.7 (see this post
   [http://wp-event-organiser.com/blog/1-7-ready-for-beta-testers-translators/](http://wp-event-organiser.com/blog/1-7-ready-for-beta-testers-translators/)).
 * Currently its in beta – but should be out sometime this week.
 *  Thread Starter [glenndm](https://wordpress.org/support/users/glenndm/)
 * (@glenndm)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226465)
 * [@nisamp17](https://wordpress.org/support/users/nisamp17/): please read the above
   posts too.
 * relevant code excerpt:
 *     ```
       if( isset( $wp->query_vars['Season'] )) {
       		$events = eo_get_events(array('event-category'=>  $wp->query_vars['Season'] ));
       		print '<div id="title_important" ><b>Kampioenschap - Championnat '. $wp->query_vars['Season'].'</b></div>';
   
       	} else {
       		$events = eo_get_events(array('numberposts'-1));
       	}
       ```
   
 * I filter on category Season (=year), because it suited my purpose better.
    The
   result: [http://www.kartcross.be](http://www.kartcross.be) (Menus are a bit wonky)
   The update Stephen (Hi!) is working on will filter on the post dates.
 *  [nisamp17](https://wordpress.org/support/users/nisamp17/)
 * (@nisamp17)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226466)
 * hi glenndm
 * Actually i want to list the new added events on my header menu as you done in
   previous post.. With that in each of my event page i have to add dynamic sidebar
   containing Organizing Commitee, Registration, Venue details, etc.. when a next
   event adding the sidebar menus may be differ..can you pls help me..?
 * Hopefully
    Nisam
 *  [nisamp17](https://wordpress.org/support/users/nisamp17/)
 * (@nisamp17)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226467)
 * hi…
 * I want to list the new added events on my header menu.. With that in each of 
   my event page i have to add dynamic sidebar containing Organizing Commitee, Registration,
   Venue details, etc.. when a next event adding the sidebar menus may be differ..
   anyone can you pls help me..?
 * see the example site..
    [http://www.hacu.net/hacu/HACU_101.asp](http://www.hacu.net/hacu/HACU_101.asp)
 * here in conference menu they annually adds the conferences..then each conference
   page contains different sidebars.. can you pls help me to do the similar..
 * Hopefully
    Nisam

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘yearly filter events using menu ?’ is closed to new replies.

 * ![](https://ps.w.org/event-organiser/assets/icon-256x256.png?rev=978123)
 * [Event Organiser](https://wordpress.org/plugins/event-organiser/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/event-organiser/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/event-organiser/)
 * [Active Topics](https://wordpress.org/support/plugin/event-organiser/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/event-organiser/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/event-organiser/reviews/)

 * 8 replies
 * 3 participants
 * Last reply from: [nisamp17](https://wordpress.org/support/users/nisamp17/)
 * Last activity: [13 years, 4 months ago](https://wordpress.org/support/topic/yearly-filter-events-using-menu/#post-3226467)
 * Status: resolved