Hello,
Can anyone help me with pre-populated ACF repeater in innerblock template?
$template = array(
array('core/heading', array(
'level' => 2,
'placeholder' => 'Schrijf de titel',
)),
array('core/paragraph', array(
'placeholder' => 'Schrijf tekst',
)),
This is a repeater field with 3 sub_fields - Link - Color - Icon
array('acf/tf-buttons', array(
)),
Something like this?
array('acf/tf-buttons', array('data' => array('text_field'=> 'Test!'))),
);
global $allowed_jsx_blocks;
echo '<InnerBlocks template="' . esc_attr( wp_json_encode( $template ) ) . '" allowedBlocks="' . esc_attr( wp_json_encode( $allowed_jsx_blocks ) ) . '" />';
I have this problem often and never found a solution to Pre Populate acf repeater fields
I tried this, but doesn’t fill the repeater field:
This is a simpel repeater field with one text field
array('acf/tf-buttons',
array('data' =>
array('test_rep'=>
array('data' =>
array('test_rep_text'=> 'test')
)
)
)
),
If you’re looking for assistance with a pre-populated Advanced Custom Fields (ACF) repeater in an inner block template, consider contacting skilled developers or seeking online tutorials offering step-by-step guidance. Trolling forums or communities dedicated to WordPress products could also provide valuable insights. Remember, industry and thorough research often produce fruitful results. For additional help with your specific ACF needs, technical platforms offering technical support might be helpful. Lastly, if you require assistance with academic tasks, consider seeking the Best Assignment Writing Help UK to ensure top-notch quality and timely submissions.
I am a skilled developer.. There is no information online that explains how to pre-populate repeater fields in a Innerblock template.
There are some tutorials/information about pre-population fields in a Innerblock template but nothing about repeater fields.
So thanks for your offer but I’m searching for a simple push in the right direction. And i’m pretty close with the array stacking in my last code snippet.
Got the solution 🙂
If you want to repeat an other button change 0 to 1
array('tatof/button', array(
'data' => [
'template_buttons_0_tb_button' => [
'title' => 'Button title',
'url' => '#',
'target' => ''
],
'_template_buttons_0_tb_button' => 'field_637e1739ba382',
'template_buttons_0_tb_color' => 'primary',
'_template_buttons_0_tb_color' => 'field_637e1750ba383',
'template_buttons_0_tb_icon' => '',
'_template_buttons_0_tb_icon' => 'field_637e18cfba384',
'template_buttons' => 1,
'_template_buttons' => 'field_637e171dba381',
]
)),
Repeater:
'template' => array(
array('core/columns', array(), array(
array('core/column', array(), array(
array('core/paragraph', array(
'placeholder' => 'Intro tekst hier'
)),
array('tatof/button', array(
'data' => [
// Button one
'template_buttons_0_tb_button' => [
'title' => 'Voorbeeld knop',
'url' => '#',
'target' => ''
],
'_template_buttons_0_tb_button' => 'field_637e1739ba382',
'template_buttons_0_tb_color' => 'secondary',
'_template_buttons_0_tb_color' => 'field_637e1750ba383',
'template_buttons_0_tb_icon' => '',
'_template_buttons_0_tb_icon' => 'field_637e18cfba384',
// Button two
'template_buttons_1_tb_button' => [
'title' => 'Voorbeeld twee',
'url' => '#',
'target' => ''
],
'_template_buttons_1_tb_button' => 'field_637e1739ba382',
'template_buttons_1_tb_color' => 'primary',
'_template_buttons_1_tb_color' => 'field_637e1750ba383',
'template_buttons_1_tb_icon' => '',
'_template_buttons_1_tb_icon' => 'field_637e18cfba384',
'template_buttons' => 2,
'_template_buttons' => 'field_637e171dba381',
]
)),
)),
array('core/column', array(), array(
array('acf/tf-image', array()),
)),
)),
),
@tatof thank you for posting your solution! This was so helpful!
I did manage to prepopulate the fields in my repeater. But there is one thing I cannot seem to figure out: The block is not rendered untill i manually ‘touch’ one of the fields in the block. Did you also encounter this problem?
Yes I did encouter that. Only got that problem with images, its important that you load them by ID.
Also check if all the Field keys are 100% correct. like my setup above.
@tatof for me it weren’t the image fields but grouped cloned fields. I skipped the clone parent field ID, now I’ve also added these it works like a charm!
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.