Support

Account

Home Forums General Issues Check repeater rows with value before loop

Solved

Check repeater rows with value before loop

  • Hi,

    I want to show a specific section in site only if a repeater has more than one row with a true/false field value = true.

    And in that section i want to loop through the repeater rows.

    So is there a way to check that without looping through all the repeater rows twice?

    Thanks!

  • When I need to do this type of thing I use output buffering.

    
    if (have_rows('repeater')) {
      ob_start();
      $display_row_count = 0;
      while (have_rows('repeater')) {
        the_row();
        if (get_sub_field('true_false')) {
          $display_row_count++;
          // other code
        }
      } // end while have rows
      $content = ob_get_clean();
      if ($display_row_count >= 2) {
        echo $content;
      }
    } // end if have rows
    
  • That’s a great idea! thank u very much!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.