WP_Query giving too many posts
-
$count = 3; $q = new WP_Query( array( 'orderby' => 'date', 'posts_per_page' => "{$count}" ) ); if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); // spit out the stuff endwhile; endif; wp_reset_postdata();
— the above provides 7 posts…not 3
$count = 3; $q = new WP_Query( array( 'orderby' => 'date', 'posts_per_page' => "{$count}" ) ); $counter = 0; if ( $q->have_posts() ) : while ( $q->have_posts() && $counter++ < $count ) : $q->the_post(); // spit out the stuff endwhile; endif; wp_reset_postdata();
Of course, this limits it to 3 posts…
But WHY won’t the first work and show just 3?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘WP_Query giving too many posts’ is closed to new replies.