技術ブログ
wordpressでカスタム投稿タイプ毎にsearch.phpのテンプレートを設定する方法
オジマネさんの「プラグインいらず!カスタム投稿タイプごとの絞り込み検索機能実装」を参考にさせていただきました。
オジマネさんのブログでは、検索フォームの設置についても詳しく書かれているのでおすすめです。
function.phpに下記のコードを入れる事で対応が可能です。
add_filter('template_include','custom_search_template');
function custom_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;
}
大阪のホームページ制作会社TREVOでは、ホームページ制作に関する情報を掲載しています。最短2日で仮サイトを公開するサービスやSEO対策に特化したホームページ制作、オリジナルホームページデザイン、ライティング、リスティング広告、WEBマーケティングなどのサービスをご紹介しています。