Support

Account

Home Forums Add-ons Repeater Field Only get first row Repeater Field

Helping

Only get first row Repeater Field

  • I have a repeater filed called “images” and inside it I have a sub_filed called “image”.

    How can I get only the first row value?

    Here is my code

    
    <?php if( have_rows('images') ): ?>
    <?php
    $active = 'active';
    while ( have_rows('images') ) : the_row();
    $image = get_sub_field('image');
    if($image == "" ) continue;
    ?>
    <img src="<?php echo get_template_directory_uri(); ?>/files/images/<?php the_sub_field('image'); ?>" class="img-fluid" />
    <?php $active = '';
    endwhile;
    ?>
    <?php endif; ?>

    What I tried (this results in an error)

    <?php if( have_rows('images') ): ?>
        <?php
        $active = 'active';
        while ( have_rows('images') ) : the_row();
        $image = get_sub_field('image');
        if($image == "" ) continue;
        ?>
        <img src="<?php echo get_template_directory_uri(); ?>/files/images/<?php the_sub_field('image'); ?>" class="img-fluid" />
        <?php break;
        <?php $active = '';
        endwhile;
        ?>
        <?php endif; ?>

    Many thanks in advance!

  • The issue is that you have 2 opening <?php tags without a closing ?> tag between them (after break;)

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.