title: Advanced Custom Fields - looping through repeater subfields and displaying a specific subfield attribute of each repeater field
body: <p>First of all, I know, I'm very average in PHP, I've <code>echo</code>'ed the whole HTML, it's awful, but that's not the case. So I'm trying to create an ACF block repeater. My goal is that I output a grid of images (cards), and when I click on any of them, a video displays on screen and below the video, a person's first and last name.</p>
  <p>So what I've done so far is that I've successfully generated the grid, but I'm stuck on the video part. The video is displaying, but the text is not. Every grid item is meant to have an individual video, right now it's hard-coded with an embed link.</p>
  <p>This is how it's meant to be: <a href="https://i.stack.imgur.com/F1tjY.png" rel="nofollow noreferrer">link</a></p>
  <p>As I couldn't figure out a way to get the <code>$row</code> elements from the <code>foreach</code> loop, I tried defining them in the beginning of the code, but without a loop, it's not gonna display anything.</p>
  <p>I hope to get some advice for a loop or some other solution to display each grid item's individual video and text.</p>
  <p>The PHP code:</p>
  <pre><code>&lt;?php 
  $rows = get_field('video');
  
  //Not sure if this is necessary
  $name1 = get_sub_field('name');
  $surname1 = get_sub_field('surname');
  
  if( $rows ) {
      echo '&lt;div class=&quot;grid&quot;&gt;';
      foreach( $rows as $row ) {
          $image = $row['thumbnail'];
          $name = $row['name'];
          $surname = $row['surname'];
          $numberoforder = $row['number'];
          $class = $row['additionalclass'];
          echo '&lt;div class=&quot;img ',$class,'&quot; onclick=&quot;openVideo()&quot;&gt;';
              echo '&lt;div class=&quot;name oswald-regular&quot;&gt;&lt;p&gt;',$name, '&lt;br&gt;' ,$surname, '&lt;/p&gt;&lt;/div&gt;';
              echo '&lt;img src=',$image,'&gt;';
              echo '&lt;div class=&quot;number-of-order oswald-md2&quot;&gt;&lt;p&gt;',$numberoforder,'&lt;/p&gt;&lt;/div&gt;';
          echo '&lt;/div&gt;';
      }
      echo '&lt;/div&gt;';
      echo '&lt;div class=&quot;show-more-btn&quot;&gt;';
      echo '&lt;input value=&quot;Show more&quot; id=&quot;btn&quot; type=&quot;button&quot; class=&quot;button&quot; onclick=&quot;displayStories()&quot;&gt;';
      echo '&lt;/div&gt;';
      echo '&lt;div class=&quot;personal-video&quot; id=&quot;personal-video&quot;&gt;';
      echo '&lt;div class=&quot;video-container&quot;&gt;';
      echo '&lt;div class=&quot;closeBtn&quot;&gt;&lt;img src=&quot;/wordpress/wp-content/uploads/2020/11/close2.png&quot; alt=&quot;Close&quot; onclick=&quot;closeVideo()&quot;/&gt;&lt;/div&gt;';
      echo '&lt;iframe width=&quot;560&quot; height=&quot;415&quot; src=&quot;https://www.youtube.com/embed/1PalAURGxtM?rel=0&amp;amp;modestbranding=1&amp;amp;controls=0&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen id=&quot;video1&quot; onclick=&quot;playPause()&quot;&gt;&lt;/iframe&gt;'; //I'd want to display an individual video for each element also
          echo '&lt;h3 class=&quot;oswald-md2&quot;&gt;'; 
               echo $name1, &quot; &quot; ,$surname1; //This is what I'm struggling with - displaying the info
          echo '&lt;/h3&gt;';   
      echo '&lt;/div&gt;';
      echo '&lt;/div&gt;';
      
  }
  </code></pre>
  <p>Thanks in advance.</p>