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'); ?>
Da Categorie(s): Code, Custom Post Types, Plugins, Wordpress