@hube2 And THAT solved it! Brilliant. Thank you so much.
I think this part in the ACF block documentation is the problem… so I’m not sure if there’s a way to do what I want to do: “This prevents the $post_id parameter from working as expected in our template functions.”
Thank you @hube2! I wrote more above but forgot to tag you.
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;
}
Oh, wow — I want to jump through the screen and hug you! I’m going to pick that apart and study what you did.
And thanks for pointing out that the div should have a class not an id. Left in from when I only had one div containing it all. Thank you!