概要
WordPressを使用しています。
数百件の投稿データがあるカスタム投稿をページネーション付きでプロントページにタームを基準に一覧表示をしたいのですが、全件表示になってしまいページ跨ぎができない状態です。
アドバイスや情報に過不足あればご指摘いただけると幸せます。
カスタム投稿の詳細
表示したい場所
フロントページ
カスタム投稿(スラッグ)
おやつ(oyatsu)
タクソノミー(スラッグ)
甘い(sweet)
ターム(スラッグ)
プリン(purine)
ケーキ(cake)
アイスクリーム(icecream)
マカロン(macaron)
表示したい並ばせ方
タームを基準に表示したい
ターム | 投稿タイトル | custom fieldA | custom fieldB |
---|---|---|---|
プリン | 北九州◯◯◯店 | ほげほげ | ★☆☆ |
プリン | 天神◯◯◯店 | ほげほげ | ★★☆ |
ケーキ | 大分◯◯◯店 | ほげほげ | ★☆☆ |
ケーキ | 別府◯◯◯店 | ほげほげ | ★☆☆ |
アイスクリーム | 薬院◯◯◯店 | ほげほげ | ★☆☆ |
アイスクリーム | 博多◯◯◯店 | ほげほげ | ★☆☆ |
アイスクリーム | 行橋◯◯◯店 | ほげほげ | ★★☆ |
マカロン | 広島◯◯◯店 | ほげほげ | ★★☆ |
マカロン | 岡山◯◯◯店 | ほげほげ | ★★☆ |
マカロン | 島根◯◯◯店 | ほげほげ | ★★☆ |
前のページへ|1|2|3|4|次のページへ
使用中のコード
php
1<?php 2 // タクソノミ取得 3 $catargs = array( 4 'taxonomy' => 'sweet' 5 ); 6 $catlists = get_categories( $catargs ); 7 foreach($catlists as $cat) : // 取得したカテゴリの配列でループを回す 8?> 9 <table> 10 <thead> 11 <tr> 12 <th scope="col">ターム</th> 13 <th scope="col">投稿タイトル</th> 14 <th scope="col">custom fieldA</th> 15 <th scope="col">custom fieldB</th> 16 </tr> 17 </thead> 18 <tbody> 19 <?php 20 $args = array( 21 'paged' => $paged, 22 'posts_per_page' => 50, 23 'post_type' => 'oyatsu', 24 'area' => $cat->slug, 25 'orderby' => 'date', 26 ); 27 $my_posts = get_posts( $args ); 28 if ( $my_posts ) { // 該当する投稿があったら 29 foreach ( $my_posts as $post ) : 30 setup_postdata( $post ); 31 ?> 32 <tr> 33 <td><?php 34 if ($terms = get_the_terms($post->ID, 'sweet')) { 35 foreach ( $terms as $term ) { 36 echo esc_html($term->name) ; 37 } 38 } 39?></td> 40 <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td> 41 <td><?php the_field('customfieldA'); ?> 42</td> 43 <td><?php the_field('customfieldB'); ?> 44</td> 45 </tr> 46 <?php 47 endforeach; 48 } else { 49 echo 'このカテゴリに投稿はありません'; 50 } 51 wp_reset_postdata(); 52 ?> 53 </tbody> 54</table> 55<?php wp_pagenavi(); ?> 56<?php endforeach; ?>
あなたの回答
tips
プレビュー