[resolved] get_posts loop leaking on single page (3 posts)

  1. R.Sallee
    Posted 6 years ago #

    Please bear with me, I barely know what I'm doing here.

    I have the main loop open with <?php if (have_posts()) : ?>--it opens at the top of my html page and closes at the bottom. Somewhere in the middle, I use get_posts to show the three most recent posts using:

    <?php global $post;$myposts = get_posts('numberposts=3&order=DESC&orderby=date');foreach($myposts as $post): ?>
    	<DIV STYLE="width:100%; border-bottom:1px solid #ffffff;"><DIV STYLE="padding:5px; padding-left:10px; padding-right:10px; border-bottom:1px solid #eaeaea;"><FONT CLASS="font4"><A HREF="<?php the_permalink(); ?>"><?php the_title(); ?></A></FONT></DIV></DIV>
    <?php endforeach; ?>

    At the bottom of the page, I want to display the publish date of the main post--but I'm getting the publish date for the last of the recent three posts called by get_posts instead.

    <?php the_time('j F Y'); ?>

    Here's an example page: http://www.jadedgamefans.com/ninja250blog/miscellany/digging-dirt/

    The publish date 22 August 2009 is from post "Sur to Malibu, PART II: Malibu canyons" which is the last in the list of 3 "Latest articles." The date should be 24 November 2008, which is the publish date for the article "Digging dirt."

    What am I doing wrong here?

  2. Gerald
    Posted 6 years ago #

    Can't really tell how you structured your queries from your post above, but you can try adding a

    <?php wp_reset_query(); ?>

    to the end of the above query, after the endforeach statement.

  3. R.Sallee
    Posted 6 years ago #

    You are my hero, that worked. I place <?php wp_reset_query(); ?> directly after endforeach in the get_posts and now the date at the bottom of the page is pulling from the page's post--thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic