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 search page that display's news items using the loop below, how can I only show posts with the status "future"?

                        <?php while (have_posts()) : the_post(); ?>
                        <div <?php post_class(); ?>>
                            <div class="news-item" onclick="location.href='<?php echo the_permalink(); ?>'">
                                <h2><a href="<?php echo the_permalink(); ?>"><?php echo the_time('d.m.Y'); ?> / <?php echo the_title(); ?></a></h2>
                                <p class="news-page">
                                    <?php if (get_field('description') != "") { ?>
                                        <?php echo the_field('description'); ?>
                                    <?php } else { 
                                        $newscontent = get_the_content();
                                        $newscontent_str = strip_tags($newscontent, '');
                                        echo substr($newscontent_str,0,250) . "…";
                                    } ?>    
                                </p>
                            </div>
                        </div>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Something like this might work:

<?php while (have_posts()) : the_post(); ?>
    <?php if ( 'future' === get_post_status( the_ID() ) ) : ?>
    <div <?php post_class(); ?>>
        <div class="news-item" onclick="location.href='<?php echo the_permalink(); ?>'">
            <h2><a href="<?php echo the_permalink(); ?>"><?php echo the_time('d.m.Y'); ?> / <?php echo the_title(); ?></a></h2>
            <p class="news-page">
                <?php if (get_field('description') != "") { ?>
                    <?php echo the_field('description'); ?>
                <?php } else { 
                    $newscontent = get_the_content();
                    $newscontent_str = strip_tags($newscontent, '');
                    echo substr($newscontent_str,0,250) . "…";
                } ?>    
            </p>
        </div>
    </div>
    <?php endif; ?>
share|improve this answer

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.