Update: So, I’ve got it working by just adding the name as the ['_name']
.
I’m still not sure what ['parent']
does or if it’s necessary (doesn’t seem to be).
Hey James, thanks for the help!
I had to make a tweak to your code to get it to work. I added a counter to modify the $value array instead of building it from scratch (otherwise it replaces any value the user sets with ‘ ‘).
function my_acf_set_repeater( $value, $post_id, $field ){
// echo '<pre>'; print_r($value); echo '</pre>';
// this one should consists array of the names
$settings_values = get_field('medication_types','option');
$i = 0;
foreach( $settings_values as $settings_value ){
$value[$i]['field_582e293d22e63'] = $settings_value['type'];
$i++;
}
//echo '<pre>'; print_r($value); echo '</pre>';
return $value;
}
add_filter('acf/load_value/name=medication', 'my_acf_set_repeater', 10, 3);
I realized, though, that using indexed repeater fields is not a smart way to do this—the client could mess it up by reordering the repeater fields.
I’ll probably redo it as a normal named field repeater, then set the field names as a prefixed version of the medication types fields… that way the client can’t reorder the fields, and they can change the medication type names without wrecking the fields.
Cheers!
Just as an example, say this is the list of names in the options page:
Hospital
Pharmacy
Surgery Center
etc…
What I need to do is set those as default values in the repeater name subfields on every new post that’s created:
Row 1
-Name: Hospital
-Value: (User will set)
Row 2
-Name: Pharmacy
-Value: (User will set)
Row 3
-Name: Surgery Center
-Value: (User will set)