1

I could use some help with a post loop that seems to always be missing the most recent post. I'm guessing that my loop is somehow buggy.

My code is below. Any help is appreciated!

<?php $posts = get_posts( "category=37" ); ?>
<?php if( $posts ) : ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
  <div class="team-member">
    <a href="<?php echo get_permalink($post->ID); ?>"><img src="<?php
    $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    echo $feat_image;
    ?>" /></a>
    <h3><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title; ?></a></h3>
    <h3 class="homepage-post-title"><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_content; ?></a></h3>
    <a class="read-more-link" href="<?php echo get_permalink($post->ID); ?>">Read More</a>
  </div>
<?php endforeach; ?>
<?php endif; ?>
3
  • by chance that post is a sticky post? get_posts has this "talent" to ignore sticky posts
    – Andrei
    Aug 30, 2016 at 20:50
  • is the latest post in category 37?
    – Michael
    Aug 31, 2016 at 1:21
  • Yep, all of the posts are in category 37 and none of them are stickied. There should be eight posts showing and only 5 are being shown. Aug 31, 2016 at 14:45

1 Answer 1

0

If you don't specify posts_per_page in your get_posts you will get the default amount of posts, which is five.

Normally the offset is 0 and order is by date, so this doesn't explain why the most recent post would be missing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.