Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a loop setup to display future posts but would like to set up an if statement where if there are no future posts, it will show a certain amount of published posts. My current query below:

        <?php
            query_posts('posts_per_page=5&order=ASC&post_status=future');
            if ( have_posts() ) : while ( have_posts() ) : the_post();
        ?>

Any ideas?

share|improve this question
1  
You already have an if statement:) just make a second query. –  Wyck Dec 11 '12 at 2:57
    
What I would like to know is how to determine there are no future posts and in that case, post some older ones. –  Mister Cairns Dec 11 '12 at 3:06
3  
Your code is already doing that, that is what if ( have_posts() does. –  Wyck Dec 11 '12 at 3:20

1 Answer 1

up vote 0 down vote accepted

example:

<?php
            query_posts('posts_per_page=5&order=ASC&post_status=future');
            if ( !have_posts() ) 
            query_posts('posts_per_page=5&order=DESC&post_status=publish');
            if( have_posts() ) : while ( have_posts() ) : the_post();
?>
share|improve this answer
    
Thanks Michael that got me most of the way there. This works: <?php query_posts('posts_per_page=5&order=ASC&post_status=future'); if ( !have_posts() ) { query_posts('posts_per_page=5&order=DESC&post_status=publish'); } if( have_posts() ) : while ( have_posts() ) : the_post(); ?> –  Mister Cairns Dec 13 '12 at 4:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.