プラグイン「Custom Post Type UI」でカスタム投稿「資料請求」(product)・タクソノミー(product_category)を作成し、参考にしたコードではタクソノミーに該当するすべてのカテゴリを取得してしまいうまく分けることができない状態です。
親カテゴリAのタクソノミーページの場合は親カテゴリAに属する子タクソノミーだけ取得するというふうにするにはどうしたらいいのでしょうか。
##使用コード
<section class="type-car-list"> <?php //基礎条件 $question_conditions = array( 'post_type' => 'product', 'numberposts' => -1, 'orderby' => 'ID', 'order' => 'DESC', 'tax_query' => array(), //ここは後から設定する ); //カテゴリ取得 $category_conditions = array( 'taxonomy' => 'product_category', 'orderby' => 'id', 'order' => 'ASC', ); $categories = get_categories($category_conditions); //カテゴリ別に各タイトルを一覧表示 foreach ($categories as $category) : //タクソノミー、タームの設定 $question_conditions['tax_query'] = array( array( 'taxonomy' => 'product_category', 'field' => 'term_id', 'terms' => $category->term_id, ), ); $questions = get_posts($question_conditions); ?> <?php if (count($questions) > 0) : ?> <div class="product-catebox"> <h2 class="product-catetitle"><?php echo $category->name; ?></h2> <ul class="estate_list"> <?php foreach ($questions as $question) : ?> <li class="estate_list_btn"><a class="button" href="<?php echo get_permalink($question->ID); ?>"><?php echo nl2br($question->post_title); ?></a></li> <?php endforeach; ?> </ul> </div> <?php endif; ?> <?php endforeach; ?> </section>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/11 00:46