Support

Account

Home Forums Add-ons Repeater Field Select output inside repeater

Solved

Select output inside repeater

  • I’m leveraging the select field in a repeater to set varying image sizes

    prev-landscape : Landscape
    prev-landscape-small : Landscape (small)
    prev-portrait : Portrait

    For some reason, I’m not having any success in echoing out the correct select result in this repeater:

    $rows = get_field('grid');
        if ($rows){
    
          foreach($rows as $row){
    
            $field = get_sub_field_object('image_size');
            $value = get_sub_field('image_size');
            $size = $field['choices'][ $value ];
    
            echo '<div>';
            echo wp_get_attachment_image( $row['image'], $size );
            echo '</div>';
          }
    
        }

    Any hints as to what I’m doing wrong, here?

  • do you need the label or only the value? i think $value is enough
    echo wp_get_attachment_image( $row['image'], $value );

    if that didnt work:
    did it work when you define size directly? just to get sure that your wp_get_attachment_image is correct.

  • Thanks for your reply. I gave your suggestion a try and no luck. I also tested out whether defining directly worked and it does (I dropped ‘prev-landscape in and the images rendered at the correct size).

  • Seems as if my choice of how I set the repeater up was causing the issue. I had success with the below code:

        if( have_rows('grid') ):
         while( have_rows('grid') ): the_row();
    
          $image = get_sub_field('image');
          $value = get_sub_field('image_size');
    
          echo '<div>';
          echo wp_get_attachment_image( $image, $value );
          echo '</div>';
    
        endwhile;
        endif;
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Select output inside repeater’ is closed to new replies.