Home › Forums › ACF PRO › Unique, pre-populated repeater fields › Reply To: Unique, pre-populated repeater fields
In order to pre-populate a repeater and have unique values for each row you need to populate the entire repeater in one go.
here’s an example:
add_filter('acf/load_value/key=field_123456', 'pre_pop_repeater', 20, 3);
/* in the above the field_123456 is the field key of your repeater */
function pre_pop_repeater($value, $post_id, $field) {
if ($value != NULL) {
// if the acf value is not null then
// repeater was previously saved
// and we should not override
return $value;
}
// return an array
$value = array(
// each element of the array represents a row
array(
// this is the first row
// set value for every field in the row
// the values are field_key => value pairs
'field_678' => 'value for this field',
'field_789' => 'value for this field'
// etc...
),
array(
// this is the second row
// etc....
),
);
return $value;
}
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.