Home › Forums › Add-ons › Repeater Field › Update field with repeater + relationship › Reply To: Update field with repeater + relationship
When you update the repeater field the values need to be in a nested array, you will also need to use field keys instead of field names.
// replace field keys with your real field keys
// Sponsor -> field name(repeater field) - field key (field_XXXXXXX')
// Select sponsors -> Sub field.(relationship) - field key (field_YYYYYYY')
$repeater_value = array(
// each nested array is a row in the repeater
array(
// each row contains field key => value pairs for each sub field
// select field
'field_YYYYYYY' => array(1142,1141)
)
)
// update field using repeater field key
update_field('field_XXXXXXX', $repeater_value, $post_id);
alternately you can use update sub field explained here https://www.advancedcustomfields.com/resources/update_sub_field/
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.