■検索フォームごとに search.php を変える
<form role="search" method="get" id="searchform" class="searchform" action="">
<input type="hidden" name="search_type" value="blog">
<div id="keyword-search-wrap">
<input name="s" id="s" type="text" class="keyword-search" placeholder="例)キーワード" value="" required="required">
</div>
<div id="submit-btn-wrap">
<input name="" type="submit" class="submit-btn" value="検索する">
</div>
</form>
<input type=”hidden” name=”search_type” value=”production”>
を追加する。 value=”blog”の部分を作成した検索結果表示PHPの名前に合わせる
(作成したPHP:search-production.php)
■新検索結果ページの作成
search.phpをコピーしてearch-production.phpに名前を変更、
内容を書き換える
■functions.phpに振り分け用のコードを追加
// 検索フォームごとに search.php を変える
add_action('template_include', 'my_search_template');
function my_search_template($template)
{
$type = filter_input(INPUT_GET, 'search_type');
$new_template = '';
if ($type) {
switch ($type) {
case 'news':
$new_template = STYLESHEETPATH . '/search-news.php';
break;
case 'blog':
$new_template = STYLESHEETPATH . '/search-blog.php';
break;
default:
$new_template = '';
}
}
if ($new_template) {
if (file_exists($new_template)) {
return $new_template;
}
}
return $template;
}