Skip to content

Instantly share code, notes, and snippets.

@zanematthew
Created April 26, 2012 14:42
Show Gist options
  • Save zanematthew/2500025 to your computer and use it in GitHub Desktop.
Save zanematthew/2500025 to your computer and use it in GitHub Desktop.
Filters for WordPress Template Redirect with Custom Taxonomies and Custom Post Types
<?php
/**
* An "easier" interface for interacting with WordPress' template_redirect function.
*
* @package zm-wordpress-helpers
* @uses is_admin()
* @uses get_query_var()
*/
function bmx_race_schedule_redirect( $params=array() ) {
if ( get_query_var('post_type') ) {
$post_type = get_query_var('post_type');
} else {
global $post;
if ( $post )
$post_type = $post->post_type;
}
$post_type = 'event';
if ( $post_type != 'event' )
return;
$template = array(
'post_type' => 'event',
'single' => plugin_dir_path( __FILE__ ) . 'theme/single-bmx-race-event.php',
'archive' => plugin_dir_path( __FILE__ ) . 'theme/search-bmx-race-event.php',
'search' => plugin_dir_path( __FILE__ ) . 'theme/search-bmx-race-event.php',
'taxonomy' => array(
array(
'taxonomy' => 'attendee',
'template' => plugin_dir_path( __FILE__ ) . 'theme/attendee-dashboard.php'
)
),
'default' => plugin_dir_path( __FILE__ ) . 'theme/index.php'
);
do_action( 'zm_template_redirect', $template );
}
add_action('template_redirect', 'bmx_race_schedule_redirect', 6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment