カスタムタクソノミーに、設定したタームを検索フォームに呼び出しプルダウンメニューとチェックボックス表示で複数選択できるように設定しました(絞り込み検索のような機能です)
検索結果(search.php)にはタームに付随する記事が表示されたので機能としては動いてるのですが、その際に選ばれたタームの表示は可能でしょうか?
検索結果画面に、このようなキーワードが表示できるようにしたいと考えてます↓
●選択されたキーワード
■ラーメンの種類:
とんこつ、しょうゆ、激辛
■ラーメンがおいしい地域:
池袋、新宿、品川
検索用PHPソース <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>"> <input type="hidden" name="s"> <input type="hidden" name="post_type" value="area" /> <div> <span>ラーメンの種類</span> <select id="input-id" name="area_all"> <option value="" selected="true">指定なし</option> <?php $terms = get_terms('タクソノミー名A' , 'get=all'); foreach($terms as $term){ echo '<option value="' . $term->slug . '">' . esc_html($term -> name) . '</option>'; } ?> </select> </div> <div> <span>ラーメンがおいしい地域</span> <?php $terms = get_terms('タクソノミー名B' , 'get=all'); foreach($terms as $term){ echo '<li><label><input value="' . $term->slug . '" type="checkbox" name="タクソノミー名B[]">' . esc_html($term -> name) . '</label></li>'; }?> </div> <input type="submit" id="searchsubmit" value="この条件で検索する" class="submit"/> </form>
検索結果PHP <?php if( !empty($cat_area) || !empty($post_tag) ) { ?> <ul> <?php if( have_posts() ): while ( have_posts() ) : the_post(); ?> <li> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; else: endif; ?> </ul> <?php } else{ ?> <ul> <?php if( have_posts() ): while ( have_posts() ) : the_post(); ?> <li> 検索ヒット時の内容を表示 </li> <?php endwhile; ?> <?php else : ?> <p>一致する情報は見つかりませんでした。</p> <?php endif; ?> </ul> <?php } ?>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/06 03:38