Home › Forums › Add-ons › Repeater Field › Create New Repeater Subfield row through code › Reply To: Create New Repeater Subfield row through code
The problem with your workaround is that you’re not updating adding the needed field_key in addition to your value. For more information on field keys see this page http://www.advancedcustomfields.com/resources/update_field/
http://www.advancedcustomfields.com/resources/update_sub_field/
Your first example I think that you’re using update_sub_fields wrong, but I’m not sure. When I’m inserting new data into a repeater I generally go with your second example and insert the keys.
Also, if you use update field on the repeater field itself and provide the correct array it will add the sub fields for you, for example:
$repeater_value = array(
// a nested array for each row
array(
// an element for each field
'subfield_1' => 'value 1',
'subfield_2' => 'value 2'
),
// a nested array for each row
array(
// an element for each field
'subfield_1' => 'value 1',
'subfield_2' => 'value 2'
),
)
update_field('repeater_field', $repeater_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.