Forums

[resolved] Display (most recent) future posts in list? (8 posts)

  1. shakingpaper
    Member
    Posted 3 years ago #

    Hi there,

    I have a loop (an events loop) where I want to show upcoming events. It is almost working but it is showing the posts that are farthest in the future. I have tried sorting by ASC and DESC but nothing seems to change.

    get_posts('cat=4&showposts=2&post_status=future&order=ASC');

    Any thoughts?

    Thanks!

  2. MichaelH
    Volunteer
    Posted 3 years ago #

    This worked just fine for me in my sidebar.php using the WordPress Default theme:

    <?php
    $args = array(
      'cat' => 3,
      'post_status' => 'future',
      'numberposts' => 3
      );
    $posts=get_posts($args);
    if ($posts) {
      foreach($posts as $post) {
        setup_postdata($post);
        ?>
        <?php the_time('m.d.y') ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
        <?php }
      }
    ?>

    Make sure you don't have any plugins causing the problem.

  3. shakingpaper
    Member
    Posted 3 years ago #

    Hmmm, that didn't seem to do the trick.

    Here is the whole loop/argument:

    <?php
    	    global $post;
    	    $the_newest = get_posts('cat=4&amp;showposts=2&amp;post_status=future&amp;order=ASC');
    	    $the_newer = get_posts('cat=3&amp;showposts=2');
    	?>
    
    		<ul id="events">
    			<?php foreach($the_newest as $post) :
      			setup_postdata($post);  ?>
    			<li class="news_post_1" id="post-<?php the_ID(); ?>">
    			<h2><a href="<?php echo get_permalink(); ?>"><?php if (strlen($post->post_title) > 25) { echo substr(the_title($before = '', $after = '', FALSE), 0, 25) . '...';} else {the_title();} ?></a></h2>
    			<p><?php the_date('l j F, Y') ?> | <a href="<?php echo get_permalink(); ?>">More...</a></p>
    			</li>
    			<?php endforeach; ?>
    		</ul>
    
    		<ul id="news">
    			<?php foreach($the_newer as $post) :
    			setup_postdata($post);  ?>
    			<li class="news_post_1" id="post-<?php the_ID(); ?>">
    			<h2><a href="<?php echo get_permalink(); ?>"><?php if (strlen($post->post_title) > 25) { echo substr(the_title($before = '', $after = '', FALSE), 0, 25) . '...';} else {the_title();} ?></a></h2>
    			<p><?php the_date('l j F, Y') ?> | <a href="<?php echo get_permalink(); ?>">More...</a></p>
    			</li>
    			<?php endforeach; ?>
    		</ul>

    Could the second loop be interfering?

  4. MichaelH
    Volunteer
    Posted 3 years ago #

    It is almost working but it is showing the posts that are farthest in the future. I have tried sorting by ASC and DESC but nothing seems to change.

    I guess you need to better explain what it is you are trying to achieve.

  5. shakingpaper
    Member
    Posted 3 years ago #

    Basically I have a footer on a site that has two sets of post feeds.

    I have an linked image here (site isn't live yet)
    http://test.shakingpaper.com.au/image/footer.png

    The events are all in the future but the loop is showing the posts that are farthest in the future when I would like to show the ones that are coming up closest to the current time.

    Hope that makes sense.

  6. MichaelH
    Volunteer
    Posted 3 years ago #

    Ah, see the issue...it looks like there is no valid DATE field to sort on as the date for those 'future' posts is not yet SET.

    Maybe you can do 'orderby'=> ID and 'order'=> ASC

  7. shakingpaper
    Member
    Posted 3 years ago #

    I ended up just using this plugin: http://coffee2code.com/wp-plugins/get-upcoming-or-past-posts/
    And it is working fine. Very customisable so all good.

    Thanks for your time and advice.

  8. sambo123
    Member
    Posted 2 years ago #

    Hi- I'm having a slightly similar issue. I have a newsletter that lists future events. I want the newsletter to only show the next 7 posts in the future. When it does the count, it also includes previous posts in the count but doesn't dispay them.
    So, if I set numberposts=7, and there's 4 posts that appear in the past, it shows the next 3 posts. Does that makse sense? What I want is for it to show the next 7 posts in the future, regardless of how many posts appear in the past. Any help would be greatly appreciated.
    Here's the code:

    <?php
    $lastposts = get_posts('numberposts=7&category=4&order=ASC&post_status=future,publish');
     foreach($lastposts as $post) :
        setup_postdata($post);
    	if(is_category('newsletter')) {
    		if(strtotime($post->post_date) < time())
    			continue;
    			}
    ?>
    <!-- stuff goes here -->
     <?php endforeach;   ?>

Topic Closed

This topic has been closed to new replies.

About this Topic