Support

Account

Home Forums Front-end Issues Relationship Field Image Size

Helping

Relationship Field Image Size

  • I have a relationship field that is rendering content summary at the bottom of a page template with a custom image size. However, when I’m trying to call the image field from the related post, I can’t seem to get it to render. I’ve tried a bunch of different stuff, but no luck as of yet. Can you please help?

    <?php 
     
    $posts = get_field('page_highlights');
    
    if( $posts ): ?>
    <div id="page-highlights">
    <?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) 
    $attachment_id = get_field('page_header_image'); // NOTE: field set to return image ID
    $size = "listing_thumb"; ?>
    
    <div class="listing-row">
    <?php if(get_field('page_header_image')) {echo wp_get_attachment_image( $attachment_id, $size );} ?>
    </div>
    <?php endforeach; ?>
    </div><!-- /#page-highlights-->
    <?php endif; ?>
  • I managed to figure this out. Pasting the updated code for everyone else that has this question.

    The key was in calling the variables, you have to call it specifically from that post’s data.

    $attachment_id = get_field('page_header_image',$p->ID);

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

The topic ‘Relationship Field Image Size’ is closed to new replies.