こんにちは、@taichi_kimuraです。
ACFの柔軟フィールドで投稿一覧を取得して出力しようとしたら、posts_per_pageが効かなかったので、忘備録。
今日は時間がないので、結果だけ書いておきます。
codexにある普通のループに表示される投稿数を指定する。
<?php
//パラメーター
$paged = (int) get_query_var('paged');//ページ送りをする場合
$args = array(
'posts_per_page' => 6,//表示件数
'paged' => $paged,
);
// The Query
$the_query = new WP_Query( $args );
if($the_query->post_count > $the_query->found_posts){
//表示する投稿数が表示したい投稿数に満たないとおかしなことになるので、if分で分岐
$the_query->post_count = 6; //表示件数
}
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
/* Restore original Post Data */
wp_reset_postdata();
} else {
// no posts found
}
