Skip to content

Instantly share code, notes, and snippets.

@hissy
Created January 8, 2013 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hissy/4483968 to your computer and use it in GitHub Desktop.
Save hissy/4483968 to your computer and use it in GitHub Desktop.
simple WordPress plugin that enables use of post type search templates
<?php
/*
Plugin Name: Enable Post Type Search Template
Description: you can use search-{$post_type}.php
Author: Takuro Hishikawa
Version: 0.1
*/
function enable_post_type_search_template($template){
if ( is_search() ) {
$post_types = get_query_var('post_type');
foreach ( (array) $post_types as $post_type )
$templates[] = "search-{$post_type}.php";
$templates[] = 'search.php';
$template = get_query_template('search',$templates);
}
return $template;
}
add_filter('template_include','enable_post_type_search_template');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment