カスタム投稿(例:サークルというカスタム投稿とお知らせというカスタム投稿、みたいなね)別に
それぞれ検索フォームを設置した際にその検索結果を出すページもそれぞれ準備したいなと思いググったメモ。
function.phpに下記追加
// テンプレート読み込みフィルターをカスタマイズ
add_filter('template_include','custom_search_template');
function custom_search_template($template){
// 検索結果の時
if ( is_search() ) {
// 表示する投稿タイプを取得
$post_types = get_query_var('post_type');
// search-{$post_type}.php の読み込みルールを追加
foreach ( (array) $post_types as $post_type )
$templates[] = "search-{$post_type}.php";
$templates[] = 'search.php';
$template = get_query_template('search',$templates);
}
return $template;
}
WordPressフォーラムの検索結果ページを振り分けたいより。
あとはsearch-circle.phpとかsearch-topics.phpみたいなそれぞれのカスタム投稿の検索結果ページを準備すればうまくいきました。
フォーム側でpost_typeで振り分けてあげるのを忘れないように~!
WordPressのサイト内検索の検索条件をカスタマイズするが参考になります。