前提・実現したいこと
WordPressでカスタム投稿ごとの検索を作りたいのですが、うまくいきません。
いろいろ検索すると下記のコードを追加し、
<input type="hidden" name="cat" value="カテゴリーID">
functions.phpに下記を追加
//カスタム投稿用post_typeセット
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[] = "{$post_type}-search.php";
$templates[] = 'search.php';
$template = get_query_template('search',$templates);
}
return $template;
}
page-gra.phpとsearch-gra.phpも作ったのですが、うまくいきません。
どなたかご教示いただけませんでしょうか。
どうぞよろしくお願いいたします。
該当のソースコード
<form method="get" action="<?php bloginfo( 'url' ); ?>#kekka"> <p style="display:none;"><input name="s" id="s" type="text" /></p> <?php $tags = get_tags(); if ( $tags ) : ?> <p>勤務地<br> <select name='tag' id='tag'> <option value="" selected="selected"></option> <?php foreach ( $tags as $tag ): ?> <option value="<?php echo esc_html( $tag->slug); ?>"><?php echo esc_html( $tag->name ); ?></option> <?php endforeach; ?> </select> </p> <span class="kakeru sp"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/career/cross.png" alt=""/></span> <p>職種<br> <?php wp_dropdown_categories('depth=0&orderby=name&hide_empty=1&show_option_all= '); ?> </p> <?php endif; ?> <input type="hidden" name="cat" value="gra"> <p><input type="image" id="submit" src="<?php bloginfo('stylesheet_directory'); ?>/images/career/btn_search.png"></p> </form>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/07 05:13