vendredi 26 décembre 2014

WP_Query condition affects posts_per_page count


I'm trying to create a new WP_Query that displays the last 5 posts from cat 1 that doesn't have a thumbnail. This actually works:



<?php
$the_query = new WP_Query( 'cat=1&posts_per_page=5' );
while ( $the_query->have_posts() ) :
$the_query->the_post(); if ( ! has_post_thumbnail() ) { ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php } endwhile;
wp_reset_query();
wp_reset_postdata();
?>


But let's say of the last 5 posts, 3 have the thumbnail; in this case, only 2 posts are displayed. I'd like to have 5 as fixed number of posts_per_page and if in the loop end up posts with thumbnail the older posts are displayed (to reach the number of 5), instead of displaying just the 2 without thumbnails.


I tried putting the if before $the_query but it didn't work.





Aucun commentaire:

Enregistrer un commentaire