カテゴリーで絞り込み検索をし、属している記事を表示しなければなりません。
※カテゴリーは、チェックボックス形式で表示したい
※とあるカテゴリーの子カテゴリーを表示したい
そのため、<?php get_search_form(); ?>を使用して検索欄を表示しようと、searchform.phpに以下の記述をしました。
php
1<div class="search-form"> 2 <form method="get" id="searchform" action="<?php bloginfo('url'); ?>"> 3 <input type="text" name="s" id="s" placeholder="検索" /> 4 <div class="search-form__title"> 5 <i class="fas fa-search"></i> 6 かんたん検索 7 </div> 8 <div class="flex"> 9 <?php 10 $args = array( 11 'include' => array( 12 get_category_by_slug("hogehoge1")->cat_ID, 13 get_category_by_slug("hogehoge2")->cat_ID, 14 get_category_by_slug("hogehoge3")->cat_ID, 15 get_category_by_slug("hogehoge4")->cat_ID, 16 get_category_by_slug("hogehoge5")->cat_ID, 17 get_category_by_slug("hogehoge6")->cat_ID 18 ), 19 'orderby' => 'term_group' 20 ); 21 $categories = get_categories($args); 22 foreach($categories as $category): 23 ?> 24 25 <label> 26 <input type="checkbox" name="catnum[]" value="<?php echo $category->term_id; ?>"> 27 <?php echo $category->name; ?> 28 </label> 29 30 <?php endforeach; ?> 31 <input class="input-button" type="submit" value="検索" /> 32 </div> 33 </form> 34</div>
しかし、foreachの中身の書き方がおかしいせいか、検索欄が表示されません。
過去に、この書き方で表示したことあるのですが、何故か表示できない減少が起きています。
お手数ですが、どこの記述が間違えているのかを教えていただけると幸いです。
よろしくお願いします。
array ( 5 => WP_Term::__set_state(array( 'term_id' => 39, 'name' => 'ほげほげ1', 'slug' => 'hogehoge1', 'term_group' => 0, 'term_taxonomy_id' => 39, 'taxonomy' => 'category', 'description' => '', 'parent' => 33, 'count' => 1, 'filter' => 'raw', 'cat_ID' => 39, 'category_count' => 1, 'category_description' => '', 'cat_name' => 'ほげほげ1', 'category_nicename' => 'hogehoge1', 'category_parent' => 33, )), )
回答1件
あなたの回答
tips
プレビュー