Although following code is for WordPress, but my question is more about general PHP loop.
I want to get posts of last 7 days. I want to get only last 7 days which have posts. If some day does not have any post, it should skip to next day.
I am using following loop to get posts from last 7 days, but the problem is that if a day does not have post, it will loop through last 7 days only, no matter if there's any post or not.
So, I have tried to extend $i value only if there is post, but if I place it inside the if condition, it will run infinite times. Thanks for any help about this.
$day = date('j');
while( $i <= 7){
query_posts('day='$day);
if (have_posts()){
//list posts.
}
$i++;
$day--;
}