Home › Forums › General Issues › Prepopulate repeater fields? › Reply To: Prepopulate repeater fields?
Whoops. I was missing that part — thank you.
I got it to work as a repeater on posts, but when it’s a repeater inside a block it doesn’t. Maybe I need to add in the block key too? (The top key is the repeater and the key inside the array is the sub_field.)
// Add field key of the repeater
add_filter('acf/load_value/key=key=field_5cf9732cb05a', 'afc_load_my_repeater_value', 10, 3);
function afc_load_my_repeater_value($value, $post_id, $field) {
//Optional: Check for post_status otherwise published values will be changed.
if ( get_post_status( $post_id ) === 'auto-draft' ) {
$value = array();
// Add field key for the field you would to put a default value
$value[] = array(
'field_5cf979117a655' => 'Label 1'
);
$value[] = array(
'field_5cf979117a655' => 'Label 2'
);
$value[] = array(
'field_5cf979117a655' => 'Label 3'
);
}
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.