Support

Account

Home Forums ACF PRO Getting Fields from Thumbnail

Solved

Getting Fields from Thumbnail

  • Hello,

    I am wondering if it is possible to get custom fields assigned to the post thumbnail on a post. For example, in WordPress you can grab the post thumbnail caption. I am trying to grab custom text areas assigned to images

    <?php if ( $caption = get_post( get_post_thumbnail_id() )->post_excerpt ) : ?>
      <?php echo $caption; ?>
    <?php endif; ?>
  • You need to supply the $post_id value in get_field()

    
    <?php 
      $attachment_id = get_post_thumbnail_id();
      $value = get_field('field_name', $attachment_id);
    ?>
    
  • Thanks, this worked perfectly!

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

The topic ‘Getting Fields from Thumbnail’ is closed to new replies.