Home › Forums › Add-ons › Repeater Field › Dynamically populate a subfield within a repeater
Hello,
I am pulling data from an external api and I am trying to populate the custom fields with that data. So far I have been able to populate all the fields except the sub-field inside the repeater.. The structure is as follows:
Field group
– Repeater
— Sub-field
// The top level
foreach ($fillable as $key => $name) {
update_field($key, $ranking->$name, $inserted_ranking);
}
// Repeater field loop, field_5f5f3d94277a3 is the repeater field id
foreach ($fillable2 as $key2 => $name2) {
update_field('field_5f5f3d94277a3', array('field_5f5f3d94277a3' => array($key2 => $ranking->team->$name2)), $inserted_ranking);
}
// Sub-field inside the repeater, field_5f5fh3dd5277a9 is the sub-field id
foreach ($fillable3 as $key3 => $name3) {
update_field('field_5f5fh3dd5277a9', array('field_5f5fh3dd5277a9' => array($key3 => $ranking->team->localNames[0]->$name3)), $inserted_ranking);
}
Why does the data populate within the first repeater but not the second(the sub field)? How can I access the third layer and populate it with data?
Correction for the sub-field, still does not work. I’ve read that sub-fields are prefixed with the parent repeater, should I select the sub field name prefixed together with the repeater fieldname? If so how would I do that?
// Sub-field inside the repeater
foreach ($fillable3 as $key3 => $name3) {
update_field('field_5f5fh3dd5277a9', array('field_5f5f3d94277a3'=>array('field_5f5fh3dd5277a9' => array($key3 => $ranking->team->localNames[0]->$name3))), $inserted_ranking);
}
Take a look at this where I explained updating the different types of sub fields and see if it helps you https://support.advancedcustomfields.com/forums/topic/programmatically-inserting-field-with-update_field-does-not-at-_field_key-meta/#post-134616
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.