0

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>

1 Answer 1

1

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; ?>
1
  • You may also need to alter the search query to include future posts Commented Mar 27, 2017 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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