Hi! I’m looping for post_type post and outputting post title and featured image. We have an ACF field Photographer for media, and I would like to output that after the featured image in the loop, but only acf fields set for the post seems to be fetched. How can I fetch the acf field for the featured image?
Hi! When you’re looping through post_type
posts and showing the title and featured image, ACF fields connected directly to the post will show up fine with get_field()
. But if the Photographer field is attached to the featured image itself, you’ll need to grab the image ID first using get_post_thumbnail_id()
, and then pass that ID into get_field()
like this: get_field('photographer', $image_id)
. That should give you the value you’re after. This kind of setup is pretty common when working on custom themes or projects for a CMS development company.