Home Forums Add-ons Repeater Field Hide empty repeater rows Reply To: Hide empty repeater rows

  • There isn’t an easy way to accomplish what you’re doing.

    One easy solution would be to make the field field required. This would prevent the user from adding a row without selecting a file.

    The other option would be to loop through the repeater and store the values in an array and then loop over the array to create your output.

      $files = array();
      if (have_rows('repeater_field')) {
        while (have_rows('repeater_field')) {
          if (get_sub_field('repeater_files')) {
            $atachment = get_sub_field('repeater_files');
            $title = $atachment["title"];
            $url = $atachment["url"];
            $files[] = '<a href="'.$url.'">'.$title.'</a>';
          } // end if get_sub_field
        } // end while have_rows
      } // end if have_rows
      // see if there is anything in files
      if (!empty($files)) {
          <div class="box-atachment">
              foreach ($files as $file) {
                echo $file,'<br /><hr />';
      } // end if files !empty