Support » Fixing WordPress » [Plugin: The Events Calendar] how to filter event listing by category

  • I’m a complete newbie to PHP and I’m wondering if you can point me The Events Calendar “how to” documentation. I’ve checked the readme.txt file that comes with your awesome plugin, and I’ve visited the forum, but I can’t find the answer.

    I’m trying to determine whether or not The Events Calendar will allow me to display events by region without having to hack into the plugin or write some custom query for my web pages. Your readme.txt file and some forum posts seem to indicate that I can filter events by category, but I’m not sure how I would code that on my Web page (in fact I’m not sure how to call the event entries either). Is there a page of documentation that shows new users how to use the plugin, and can the events be filtered by category?

    My calendar needs to be able to pull events by region. I have seven different regions (Area 1, Area 2….. Area 7). When you click on a region, you should only be able to see events in one of those areas.

    A million thanks for any help anyone can provide…. I will happily contribute some documentation for this great plugin, if that is desired or needed.

Viewing 15 replies - 1 through 15 (of 20 total)
  • Hi enbient,

    The Dev Team will return from vacation at the end of the week. I’m sure they will provide assistance when they return. In the meantime, does anyone else have any ideas?


    – Noah

    At the moment the only way I could imagine doing this is to create a series of subcats, but it turns out when I tried it out our rewrite rules don’t support subcats.

    in conclusion, perhaps next release my friend. I put a feature request in the roadmap.

    Bump. Thnx for the plugin.
    I’m also looking forward to this feature of Event-cat subcats.

    Sidenote: not sure if you know, noticed or it’s just me; but:
    when an event post is listed in ‘events’ cat, it can be listed only in one or a number of other PARENT categories. ie Once listed in ‘Events’ the post cannot be listed in any child or grandchild cats at all.

    I also vote for this feature 🙂

    I need to allow the users to sort out the events by category, and ideally also by location. Right now, I’m using parent categories in addition to the event category.


    Hi everyone,

    I just installed The Events Calendar, and so before I add my comment, I just want to say that I tried out 5-10 different calendar plugins, and this one was by far the best, but it does need 3 crucial things before I can fully commit to it:

    1. Recurring events.
    2. Real (sub)categories and filters.
    3. Export to iCal/gCal.

    Now, back to how I got a makeshift categories system to work. Here was my temporary solution: First, I created several subcategories under Events, which you select (only 1 subcategory for each event) when you go to create an Event, that way each event is marked under “Events,” and a corresponding subcategory. Or, alternatively, no subcategory can be selected.

    Next, I corrected a small bug in /views/gridview-day.php:

    foreach((get_the_category()) as $category) {
        echo 'cat_' . $category->category_nicename . ' ';

    The old file has the actual *name* of the category, which–if the subcategory has spaces in it–just won’t work. Plus, using the nicename just seems like a better idea. Anyhow, the latest version of “The Events Calendar” assigns each event in the calendar a CSS element, so I wrote the following in my header.php file (please note that I have my “Events” category ID as 4, so that will need to change for each specific context in which this code is used):

    // if a category view see if category is a 'direct child' of cat4
    if ( is_category() ) {
    	$cat = get_query_var('cat');
    	$args = array(
    		'include' => $cat,
    			'hide_empty' => 0
    	$categories = get_categories($args);
    	if ( ($categories[0]->category_parent == 4) ) {
    		foreach((get_the_category()) as $category) {
    			if ($category->cat_ID != 4) {
    				echo "\t\t\t<style type='text/css'>\n";
    				echo "\t\t\t\t.tec-calendar td .tec-event {\n";
    				echo "\t\t\t\t\tdisplay: none;\n";
    				echo "\t\t\t\t}\n\n";
    				echo "\t\t\t\tdiv.cat_" . $category->category_nicename . " {\n";
    				echo "\t\t\t\t\tdisplay: block !important;\n";
    				echo "\t\t\t\t}\n";
    				echo "\t\t\t</style>\n";

    What this code does is detect if the current page being viewed is a subcategory of the Events category (so, the permalink URL might look something like /caetgory/events/subcategory/). If a subcategory of events is being viewed, the CSS is set to hide all events, and then display only the ones that match the nicename of the current category.

    Since it’s outputting the style tags, it should be placed in the header’s <head> tag.

    It’s kind of a dumb and simplistic trick, since all it’s doing is visually hiding things, but it gets the job done, plus the RSS feeds still give the correct corresponding data, since it relies on WordPress’s categories taxonomy architecture.

    Both of these are on the roadmap for the 1.6 release:
    2. Real (sub)categories and filters.
    3. Export to iCal/gCal.

    I kind of like your solution. Mind sending me a patch?

    Hi Shane,

    The only modifications I made to your script are the tiny change mentioned above for gridview-day.php–I just changed it from using the category’s title to using the category’s nicename. The rest of the code is theme-based and therefore outside of the-events-calendar plugin. If you’d like to contact me regarding the issue further, I can be reached at

    But, it bears mentioning that the biggest limitation with this simplistic workaround is that it only works for the current month–I haven’t figured out any way to get it to work for months that aren’t the current one since it involves changing the taxonomy, which removes the subcategory from the permalink.

    If you don’t mind me asking, what’s the time table for the 1.6 release? The reason I ask is because I’m currently working for a client on a big project that I’d like to use the-events-calendar for, and it sounds like the 1.6 update is going to be a big one. Unfortunately, the slated completion date for the project is within the next month or month and a half–my hope is that we might see a 1.6 release sometime between now and then, but perhaps that’s a bit optimistic.

    While we might make that timeline, I wouldn’t bank on it. That said, you are welcome to ping me and grab a copy of the trunk build at any time. Those features will exist long before the release comes out as they are both priority 1 (out of 5).

    That would be great–I’ll make sure to do that within the next couple of weeks. Thanks again for making an excellent plugin.

    I just want to express my opinion on the idea of filtering subcategories by hiding via CSS. It seems a reasonable temporary solution, but I don’t think that is a good long-term solution and hope the development team isn’t seriously considering doing that. Filtering categories should exclude events, not just hide them.

    Subcats will be a functioning feature in 1.6, which will allow for real filtering. Bryan’s solution is as you stated, a nice temp solution.

    Hi everyone,

    I’ve got the plugin installed and working and for me it works great! A few minor issues I have to solve before I am completely satisfied.

    I am using version 1.6.2 and in that version support has been build in to specify categories to be filtered on. This is what I wanted to do for the iCal feed as well. But it seems that this is not supported yet.

    When I use the http://[weblog]/?iCal url it will always return all events of only the parent category ‘Events’. For my events I defined sub-categories and I want to be able to specify a category for which the events should be exported in the feed.

    Any ideas how to get this to work?


    This is included in the next release. To get it now, replace the current definition of iCalFeed() in the-events-calendar.class.php with the new definition in trunk:

    I didn’t add buttons for this feature because it’s getting a little cluttered on the front end. To access it, use the url construction:

    Any opinions on how this feature should be accessed?


    That would be very nice Justin!

    Let me tell you in short what I intend to do and how I think the feature could be accessed. For this moment I only have one event calendar holding the Formula 1 racing events. I made a sub-category ‘Formule 1’ (yes, it is in Dutch) for these events and added it to the posts.

    When I want to see the Formula 1 event calendar I go to the following URL:

    On this page the iCal button is present. It would be very nice if the iCal URL that will be returned when you click on the iCal button could depend on the event category being used on the page shown. In my case that would be something like:
    I think the second solution URL is unusable because it doesn’t match the URL construction you are about to implement.

    Could my first suggestion be usable?
    I have also another relating question: Will it be possible in the future to define for which category or categories the widget will show events? Either by setting up the widget or by letting the user select the category/categories? Would be great!

    Thanks for your reply. Will try the solution and let you know the results.


    Hi Theo,

    Now the list and calendar view iCal buttons sense the sub-category, as you describe. I went with regular query string syntax because these links don’t need to be pretty since they don’t navigate anywhere and since a few people have had trouble with the rewrite rules not working.

    You can replace gridview.php and list.php with the versions from trunk to get the changes.

    I’ll suggest category filtering of the widget to the team.


Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Plugin: The Events Calendar] how to filter event listing by category’ is closed to new replies.