Created
November 8, 2011 11:50
-
-
Save jdevalk/1347575 to your computer and use it in GitHub Desktop.
Function to move searches for non-post post-types / taxonomies to their respective archives.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function yoast_change_template( $template ) { | |
global $wp_query; | |
if ( !isset($wp_query->query_vars['taxonomy']) ) | |
return $template; | |
$taxonomy = get_taxonomy( $wp_query->query_vars['taxonomy'] ); | |
if ( is_search() && count( $taxonomy->object_type ) > 0 && !in_array( 'post', array_values($taxonomy->object_type) ) ) { | |
set_query_var('post_type', $taxonomy->object_type[0]); | |
$newtemplate = get_archive_template(); | |
if ( $newtemplate ) | |
$template = $newtemplate; | |
} | |
return $template; | |
} | |
add_filter('template_include','yoast_change_template',10,1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment