Skip to content

Instantly share code, notes, and snippets.

@jasondavis
Forked from zanematthew/gist:2500025
Created May 1, 2012 18:53
Show Gist options
  • Select an option

  • Save jasondavis/2570468 to your computer and use it in GitHub Desktop.

Select an option

Save jasondavis/2570468 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