• Resolved rsallee

    (@rsallee)


    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?

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

    Thread Starter rsallee

    (@rsallee)

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_posts loop leaking on single page’ is closed to new replies.