Posts loop displaying the same post data

My first real day with WordPress, it’s not going well… I just have a simple loop where I wish to display some posts from a specific category. This is my code:

<?php 
    $args = array(
        'numberposts' => 5,
        'category' => 2,
        'offset' => 0,
        'order' => 'date',
        'post_type' => 'post',
        'post_status' => 'publish'
    );
    $foodPosts = get_posts($args);
    foreach ($foodPosts as $foodPost) : setup_postdata($foodPost); 
?>
    <div><?php the_permalink(); ?></div>
    <div><?php the_title(); ?></div>
    <div><?php the_content(); ?></div>
<?php endforeach; wp_reset_postdata(); ?>

and this is the output:

http://10.0.1.174/mysite/?p=7
Cool post title
this is yet another food post

http://10.0.1.174/mysite/?p=7
Cool post title
this post is in the food category

http://10.0.1.174/mysite/?p=7
Cool post title
this is a post about food

So the content for each is correct, but some reason all the permalinks and titles are the same as the very first post. What’s up?

Read more here: Posts loop displaying the same post data

Leave a Reply

Your email address will not be published. Required fields are marked *