The Events Calendar and Custom Post Types

The Events Calendar plugin is outstanding for tracking events within WordPress sites and blogs. The integration of templates into your own theme means you don’t risk overwriting updates each time you upgrade the plugin. This is probably the strongest event calendar plugin we’ve used, but that doesn’t mean there aren’t some tweaks that could be made. Unfortunately, all events are listed as regular posts in WordPress; this works fine, but if you’re a neat-freak like we are, you like to have everything in its own place using custom post types. Because The Events Calendar doesn’t support custom post types (yet), we have to force it a little. It’s actually pretty easy and only take a little bit of code to complete, check it out below.

On line 1029 of this file:
/wp-content/plugins/the-events-calendar/the-events-calendar.class.php

Replace this:

public function addEventBox( ) {
add_meta_box( 'Event Details', __( 'The Events Calendar', 'Events_textdomain' ),
array( $this, 'EventsChooserBox' ), 'post', 'normal', 'high' );
}

With this:

public function addEventBox( ) {
add_meta_box(
'Event Details', __( 'The Events Calendar', 'Events_textdomain' ),
array( $this, 'EventsChooserBox' ), 'post', 'normal', 'high' );
add_meta_box( 'Event Details', __( 'The Events Calendar', 'Events_textdomain' ),
array( $this, 'EventsChooserBox' ), 'events', 'normal', 'high' );
}

The word “events” on line 6 is the name of your custom post type. We use “events” because, well, they are events.

Now that the events are showing in your custom post types, you’ll need to edit the events templates, these are kept in the “events” directory within your theme. All you need to do is tweak the query to pull the custom post type, so add the following line of code right before the loop starts:

<?php query_posts('post_type=events&category_name=events&eventDisplay=upcoming'); ?>

Check out these comments...

  1. Having trouble with part 3. Can you please explain in a little more detail?

  2. ton on March 27th, 2011
  3. @ton – you’ll need to update the query for the events calendar to pull the data correctly in the templates they provide. When The Events Calendar is new and hasn’t been modded, the query looks for posts in the category “Events”. All you need to do is tweak that query to use your custom post type name instead of posts. You can find the query_posts documentation in the WordPress Codex, if you’re unfamiliar with that portion of this process.

    Let me know if you have any ther questions.

  4. serialdesigngroup on March 27th, 2011
  5. Thank you so much! It definitely worked with the list view. The only problem left is that that the template isn’t loading for the single view. Any help would def be appreciated. Thanks again!

  6. ton on March 27th, 2011
  7. @ton – can you tell me what specifically the page is doing? Is it throwing any type of error? Have you grabbed the latest version of the single.php file from the plugin views directory?

  8. serialdesigngroup on March 29th, 2011
  9. Hi,
    i am using the wordpress event calender plugin with multisites i have total 10 sub sites on network now i want to show all events listing on my first main site including the events added from the subsites as well.
    does it possible?

  10. Neeraj on August 27th, 2013

You diggin' our post? Leave a comment and let us know...