Support

Account

Home Forums Add-ons Repeater Field Getting instance and (sort of) ID of repeater field Reply To: Getting instance and (sort of) ID of repeater field

  • If you need specific identifier, not random ID or index, you can simply hash value of one of repeater fields, which you consider unique enough. It can be used to generate e.g. FAQ item permalink hash, it will be persistent enough, if you will not change question text too often.

    
    <?php if ( have_rows('faqs') ): ?>
      <?php while ( have_rows('faqs') ) : the_row(); ?>
    
        <a href="#<?php echo md5( get_sub_field('question') ); ?>">
          <?php the_sub_field('question'); ?>
        </a>
        <?php the_sub_field('answer'); ?>
    
      <?php endwhile; ?>
    <?php endif; ?>