Support

Account

Home Forums General Issues have_rows() problem showing data after data has been removed Reply To: have_rows() problem showing data after data has been removed

  • Have the fields just had content removed or have the rows been deleted. If the rows still exist but the fields are empty then the repeater still has rows. This is the only thing that I can see that could cause this.

    If this is the case what I would do is to use an output buffer and create a flag to tell me if any content exists in the sub fields.

    
    <?php 
          // add output buffer
          ob_start()
          // flag
          $has_content = false;
    ?>
    <div class="exhibitor_videos">
      <?php // Check rows exists.
        if( have_rows('exhibitor_videos') ):
          // Show header
          echo '<h2 class="entry-header">Video Gallery</h2>';
          // Loop through rows.
          while( have_rows('exhibitor_videos') ) : the_row();
            // Load sub field value.
            // add check for content
            if (get_sub_field('exhibitor_video')) {
              // update flag
              $has_content = true;
              $exhibitor_video = get_sub_field('exhibitor_video');
              $exhibitor_video_title = get_sub_field('exhibitor_video_title');
                // Do something...
               	echo '<div class="column">';
                  echo do_shortcode("[video src=" . $exhibitor_video . "]");
                  echo '<p>' . $exhibitor_video_title . '</p>';
               	echo '</div>';
            } // end if get field
            // End loop.
          endwhile;
        else : // No value.
          // Do something...
        endif;
      ?>
    </div>
    <?php 
      // get buffer
      $content = ob_get_clean();
      // only show content if there was content
      if ($has_content) {
        echo $content;
      }
    ?>