Home › Forums › Backend Issues (wp-admin) › Pre populate repeater in a flexible content
Hello,
I’m trying to pre populate a repeater inside a flexible content, using:
add_filter( 'acf/load_value/key=field_mykey', 'default_fields', 10, 3 );
add_filter( 'acf/load_value/name=content_name', 'default_fields', 10, 3 );
I’m able to:
– populate a repeater outside a flexible content
– populate a flexible content with a block
but I’m not able to pre populate a repeater inside a flexible content added dynamically with the button “add block”…
So what I would like to achieve is:
– create a new post
– the flexible content is empty
– click “add block” and add the pre populated repeater
is it somehow possible?
many thanks
Francesco
I haven’t found a solution for this but I found another solution that fit my problem, with this code is possible to pre-populate nested fields with some default value:
add_filter('acf/load_value/key=field_607879a1215fc', 'acf_load_default', 10, 3);
function acf_load_default($value, $post_id, $field)
{
if ($value === false) {
$value = array();
$value[] = array(
'field_6081eeaf5a418' => 'Example Title One',
);
$value[] = array(
'field_6081eeaf5a418' => 'Example Title Two',
'field_6081eeb75a419' => array(
array('field_6081eebf5a41a' => 'Example Title Three'),
array('field_6081eebf5a41a' => 'Example Title Four')
)
);
}
return $value;
}
That is not a solution really, its been 2 years and no response?
Unfortunately, there really isn’t a great solution available for this. When you have a flex field ACF creates a hidden copy of each layout. When you add a layout ACF copies that hidden version to create the new layout.
The correct solution would be to use the ACF JS API, see also: Adding custom javascript to fields. Because the repeater would need to be populated when the layout is added. Unfortunately I don’t now of any working examples of this to reference.
You must be logged in to reply to this topic.
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.