Support

Account

Home Forums General Issues My fields are not looping with my get_posts foreach loop

Solved

My fields are not looping with my get_posts foreach loop

  • Hello!

    I am trying to get my page built out. I have a custom archive template built, with a get_posts foreach loop created. When I echo out the other information within the object, they are all different posts, BUT when I insert some of my custom field data within the foreach loop, it only displays the fields for the FIRST post, even though the other posts are streaming in to the archive within the loop just fine.

    Any ideas about what is happening and how to fix it?

    Cheers!

  • You are outside of the normal WordPress loop so you have to pass the ID to your get_field function like this:

    foreach($myposts as $mypost) {
    
        echo get_field('myfield', $mypost->ID);
    
    }
  • This was it, thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘My fields are not looping with my get_posts foreach loop’ is closed to new replies.