まずは準備としてカスタム投稿スラッグ、カテゴリID、タクソノミー名などを取得する。
1 2 3 4 5 6 |
<?php $term_id = 2;//カテゴリーIDです。管理画面でカテゴリー表示をし、URLをみると「taxonomy=◯◯ID=●●」といった形で確認できる $taxonomy_name = 'aaa';//タクソノミー名 $post_name = 'bbb';//カスタム投稿のスラッグ $termparent = get_term( $term_id, $taxonomy_name );//親ターム取得 ?> |
次に、下記でループさせる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php $args = array( 'numberposts' => -1, 'post_type' => $post_name, 'tax_query' => array( array( 'taxonomy' => $taxonomy_name, 'field' => 'slug', 'terms' => $termparent, ), ), ); $customPosts = get_posts($args); ?> <?php if($customPosts) : ?> <?php foreach($customPosts as $post) : setup_postdata( $post ) ; ?> この中が繰り返されるので、入れたいものを入れる。 <?php endforeach; ?> <?php endif; wp_reset_postdata(); //クエリのリセット ?> |