前提・実現したいこと
検索フォームによって検索結果ページをわけたいと思い、ネットでやり方を探して試してみましたが検索結果ページが切り替わらないです。search-origin.phpにいかず、search.phpで行われてしまう状態です。(search.phpでは検索できている)
該当のソースコード
page-searchorigin.php
<form method="get" id="searchform" action="<?php echo home_url('/'); ?>"> <div class="searchContent"> <input type="text" name="s" value="<?php the_search_query(); ?>" placeholder="SEARCH"/> <input type="hidden" name="post_type" value="origin"> <div class="searchButton"> <button type="submit">検索</button> </div> </div> </form>
functions.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; }
search-origin.phpの検索結果ページにいかずsearch.phpで検索がおこなわれてしまう。
参照
回答1件
あなたの回答
tips
プレビュー