お世話になります。
何度も同じ質問をしておりますが、なんどやっても表示が成功しませんので再度質問させてください。
現在の問題は、記事の表示がターム1のみであり、また、表示件数を6件と指定しているにもかかわらず、
全投稿数が表示されます。
①以下のコードでどこが誤りなのかがわかりません。ご指摘とご説明をいただければと思います。
特に、わからない点は、
②なぜループの中にループを入れるのかが、明確に説明できない。(なんとなくそうなのかなという程度)
③WP_Queryは機能しなくて、get_postsだと表示されました(ターム1だけですが)。使い方の違いがあるのでしょうか?
前提 カスタム投稿(product) タクソノミー(brand, size) ターム1(brand→A,B,C,D,E,F,G) ターム2(size→X,Y,Z) A-G、X-Zごとに投稿記事があり、Aの投稿記事、Bの投稿記事のようにページごとに表示を変えたい。
<?php $taxonomy = array( 'brand', 'size'); $args = array( 'parent' => 0, 'hierarchical' => 0, 'hideempty' => 1, 'orderby' => 'term_order', 'order' => 'ASC' ); $terms = get_terms( $taxonomy, $args ); foreach( $terms as $term ): $termlist = array( 'post_type' => get_post_type(), 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'brand', 'field' => 'slug', 'terms' => array( $term->slug ), ), array( 'taxonomy' => 'size', 'field' => 'term_id', 'terms' => array( $term->slug ), ), ), 'posts_per_page' => 6, ); ?> <?php $myposts = get_posts( $termlist ); ?> <?php foreach ( $myposts as $post ) :?> <?php setup_postdata( $post ); ?> //ここにhtmlを表示 <?php endforeach; wp_reset_postdata(); ?> <?php endforeach;?> <div class="pagenation"> <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?> </div> <?php wp_reset_postdata(); ?>
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/05/15 16:22 編集
退会済みユーザー
2016/05/15 17:32
2016/05/16 01:05 編集