Support

Account

Home Forums ACF PRO get the featured image of a +relationship field

Unread

get the featured image of a +relationship field

  • I have a field group with ID group_61318c077c7d6.

    In that group is a field with ID field_61318c078a746, a relationship field.

    I’d like to create a Gutenberg slider block like this one, which loops over the rows of group_61318c077c7d6 and grabs the featured image of the field_61318c078a746’s related post.

    So, something like:

    <div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?>">
    <?php if( have_rows('group_61318c077c7d6') ): ?>
    <div class="slides">
    <?php while( have_rows('group_61318c077c7d6') ): the_row();
    $template = get_field('field_61318c078a746');
    if ( $template ) : $image = // get the template's thumbnail
    ?>
    <div>
    <?php echo wp_get_attachment_image( $image['id'], 'full' ); ?>
    </div>
    <?php endwhile; ?>
    </div>
    <?php else: ?>
    <p>Please add some slides.</p>
    <?php endif; ?>
    </div>

    How do I complete this code to grab the featured image of the field_61318c078a746’s related post, please?

    Help appreciated.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.