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++;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.