• Resolved Anonymous User 1789484

    (@anonymized-1789484)


    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!

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    Thread Starter Anonymous User 1789484

    (@anonymized-1789484)

    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?

    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.

    Thread Starter Anonymous User 1789484

    (@anonymized-1789484)

    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)
    https://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.

    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

    Thread Starter Anonymous User 1789484

    (@anonymized-1789484)

    I ended up just using this plugin: https://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.

    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;   ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Display (most recent) future posts in list?’ is closed to new replies.