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:

    $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:
Cool post title
this is yet another food post
Cool post title
this post is in the food category
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


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: