Support

Account

Home Forums Add-ons Repeater Field Repeater Limit, Bottom Half

Solved

Repeater Limit, Bottom Half

  • I have a repeater field which appears on a specific page, and I have a total of 6 results. I have been able to echo out only the first three, but would like to code it so I can echo out the second three, but can’t figure it out. Here is the code I’m using to echo out the first three. Help!

    <?php if(get_field('callactions','2')): $i = 0; ?>
    <?php while(has_sub_field('callactions','2')): $i++; if( $i > 3 ) { break; } ?>
    <?php $image = wp_get_attachment_image_src(get_sub_field('image_callactions'), 'mainaction-img'); ?>
    <img src="<?php echo $image[0]; ?>" alt="<?php the_sub_field('title_callactions'); ?> | <?php the_sub_field('caption_callactions'); ?>" />
    <div class="actionbtn <?php the_sub_field('button_color_callactions'); ?>"><a href="<?php the_sub_field('page_link_callactions'); ?>"><?php the_sub_field('button_title_callactions'); ?></a></div>
    <div class="captions"><h1><?php the_sub_field('title_callactions'); ?></h1><h2><?php the_sub_field('caption_callactions'); ?></h2></div>
    <?php endwhile; ?>
    <?php endif; ?>	
  • Hi @re20

    I believe you can make use of an if – else conditional statement to implement the above snippet instead of using the break.

    The code will look something like this:

    <?php while(has_sub_field('callactions','2')): $i++; if( $i < 3 ) {
    
    //do something
    }
    else{
    //do something
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Repeater Limit, Bottom Half’ is closed to new replies.