Support

Account

Home Forums Add-ons Repeater Field Getting The First Two Rows of a Repeater and Then Outputting a Nested Repeater Reply To: Getting The First Two Rows of a Repeater and Then Outputting a Nested Repeater

  • Just typing it up here and formatting it helped me work it out in my head:

    <?php if( have_rows('press_releases') ): ?>
    <h2>Press Releases <span class="sprite icon"></span></h2>
    <div>
    <?php endif; ?>
    
    <?php
       $prRows = get_field('press_releases' ); // get all the rows
       $first_row = $prRows[0]; // get the first row
       $first_row_year = $first_row['year'];
       $first_row_pr = $first_row['pr_posts'];
    ?>
    
    <h3><?php echo $first_row_year; ?></h3>
    
    <?php
       if($first_row_pr) 
          {
             foreach($first_row_pr as $pr)
             {
                echo '<h4><a href="#">' . $pr['heading'] . '</a></h4>';
                echo '<p>' . $pr['date'] . '</p>';
             }
          }
    ?>