Skip to content

Instantly share code, notes, and snippets.

@guzuri
Created October 11, 2013 00:06
Show Gist options
  • Save guzuri/6927648 to your computer and use it in GitHub Desktop.
Save guzuri/6927648 to your computer and use it in GitHub Desktop.
search.phpを読みこむデータによって振り分ける
//function.phpに追記
add_filter('template_include','custom_search_template');
function custom_search_template($template){
if ( is_search() ) {
//表示する投稿タイプを取得→それをsearch-★.phpの★部分に埋め込む
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment