• OK, guys, I need some help.

    Look at thewhineseller.com. See the Recent Posts over in the top right of the navbar? It keeps showing posts that are scheduled to post in the future instead of just the posts that have recently posted. (You can see this in action since the topmost post isn’t due to post for many days now.)

    Code I’m using is:

    <?php
          $number_recents_posts = 7;//Can be how much you want
          $recent_posts = wp_get_recent_posts( $number_recents_posts );
          foreach($recent_posts as $post){
            echo '
    <li><a>' .   $post["post_title"].'</a> </li>
     ';
          } ?>

    How would you recommend I fix this? I’m hoping I just left a line out of the code like a doofus.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Don’t use wp_get_recent_posts. Use get_posts.

    Thread Starter hdepiano

    (@hdepiano)

    This is what makes me think something more is wrong.

    I tried both ‘<?php get_posts( $args ); ?>’ and ‘<?php wp_get_recent_posts( $num ) ?>’ and both yield no results, though clearly there are posts to be found.

    The code I pasted above was the only thing I could get to work at all, if it worked wonky.

    So, I still don’t have a way to make it stop pulling posts from the future, though I appreciate your help.

    Thread Starter hdepiano

    (@hdepiano)

    Is there a way I could incorporate the ‘post_status’ => ‘published’ from get_posts as esmi suggested into the code I’m using above?

    Try:

    <?php
    $number_recents_posts = 7;//Can be how much you want
    $recent_posts = get_posts('post_status=publish&posts_per_page=' . $number_recents_posts );
    foreach($recent_posts as $post) {
    	setup_postdata($post);?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a</li>
    <?php} ?>
    Thread Starter hdepiano

    (@hdepiano)

    That gives me

    Parse error: syntax error, unexpected ‘}’

    (I tried killing the } in the code just for fun but I get the same error.)

    I think I may temporarily try to find a plugin to fix this. But seriously, WTH?

    I appreciate the help esmi!

    Try:

    <?php
    $number_recents_posts = 7;//Can be how much you want
    $recent_posts = get_posts('post_status=publish&posts_per_page=' . $number_recents_posts );
    foreach($recent_posts as $post) {
    	setup_postdata($post);?>
    	<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a</li>
    	<?php
    } ?>

    That works for me.

    Thread Starter hdepiano

    (@hdepiano)

    That works with only one small problem, it seems to override the # of posts preference to 5 instead of 7 which is weird but, you know, at this point, I’ll take it!

    I really appreciate all your help.

    For anyone else who is having a similar issue, I was also able to do a sort of “work around” using a hacked up very of Feedburners BuzzBoost. But I’ve switched that now to the code above esmi so kindly provided.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Get Recent Posts Function calls up posts scheduled in the future’ is closed to new replies.