Home › Forums › Add-ons › Options Page › Updating Values from changes on Options Page Repeater Field for Dynamic Populate › Reply To: Updating Values from changes on Options Page Repeater Field for Dynamic Populate
You can’t automatically update all the places and posts where previous values are stored. To do this you’d need to do a query to get every post where the value might be, loop through all of the posts, then go through all of the fields where it was selected, test them against the new value and update each individual post where is was saved. Might work on a small site, but this process would likely timeout your save if done on a large scale.
Rather than generating the value that is selected you should just be selecting a setting and then dynamically generating the value when it needs to be output on the page.
I know this may completely change the way the site works, and may not be possible.
for example, generating the field choices
//ACF Multiple ACF Fields to Populate Column Title Field Width Select Field
function acf_load_button_choices( $field ) {
// reset choices
$field['choices'] = array();
// if has rows
if( have_rows('button_options', 'option') ) {
// while has rows
while( have_rows('button_options', 'option') ) {
// instantiate row
the_row();
$label = get_sub_field('button_template_label');
// append to choices
$field['choices'][$label] = $label;
}
}
// return the field
return $field;
}
add_filter('acf/load_field/name=column_button_options', 'acf_load_button_choices');
On the page where you want to use it I would do something like this
// generate available button options
if( have_rows('button_options', 'option') ) {
// while has rows
while( have_rows('button_options', 'option') ) {
// instantiate row
the_row();
$button_background_option = get_sub_field('button_background_color');
// vars
$value = "background:" . $button_background_option . ';';
$label = get_sub_field('button_template_label');
// append to choices
$buttons[$label] = $value;
}
}
now where you use the value you could do something like this
$option = get_field('column_button_options');
if (isset($button[$option])) {
echo $button[$option];
}
I’m sure there are better ways to do this as well.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.