Home › Forums › Add-ons › Options Page › Multiple Options Pages w/ Multiple Instances of Dynamic Choices › Reply To: Multiple Options Pages w/ Multiple Instances of Dynamic Choices
It is very likely that you’re creating an infinite loop.
1) When ACF loads repeater 1 the filter to get the values from field 2 is called
2) This causes ACF to load repeater 2
3) When ACF loads repeater 2 the filter to get the values from field 1 is called
4) This causes ACF to load repeater 1 — loop back to #1
This can be solved in a couple of ways.
1) If you are familiar with how ACF stores the values of a repeater you can use the WP function get_option(), this avoids calling ACF functions and eliminates the infinite loop.
// example of getting repeater values without ACF functions
$repeater = 'repeater1'; // name of repeater
$count = intval(get_option('options_'.$repeater)); // gets # rows
for ($i=0; $i<$count; $i++) {
$value = get_options('options_'.$repeater.'_'.$i.'_sub_field_name';
}
2) In each filter, remove the hook for that filter and then replace it so that each filter can only be called oned.
// example of removing/replacing filter
function acf_load_uno_field_choices($field1) {
// remove this filter
remove_filter('acf/load_field/name=dropdown1', 'acf_load_uno_field_choices');
// your code to get values here
// re-add this filter
add_filter('acf/load_field/name=dropdown1', 'acf_load_uno_field_choices');
// return field
return $field1;
}
add_filter('acf/load_field/name=dropdown1', 'acf_load_uno_field_choices');
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.