Support

Account

Home Forums Add-ons Repeater Field Repeater Toggle On & Off Reply To: Repeater Toggle On & Off

  • I would add another field to my repeater, probably a true/false field to set display on/off. I would probably add some type of acf/validate_value filter to make sure that at least one row of the repeater is set to be shown because with them all set to not show the code I include would cause an infinite loop, but I would also build some kind of exit into the loop to prevent this as well.

    
    $slide = array_rand($component_fields['slides']);
    $slide = $component_fields['slides'][$slide];
    $count = 0;
    // use count to make sure we only to this X number of times to prevent infinite loop
    // and test display true/false field
    while ($count<10 && !$slide['true_false_field_name']) {
      // count is < 10 and this slide should not be shown
      // select a different slide
      $slide = array_rand($component_fields['slides']);
      $slide = $component_fields['slides'][$slide];
      $count++;
    }