There seems to be an issue with updating sub fields of a group field. It is treated as a repeater, as was discussed in the other topic.
A group field is actually a repeater that always has one row. update_sub_field() is looking for a row index in the second array index
array($repeater_key, $row_index, $sub_field_key). There is no row index for a group field and if you supply a row index ACF will save the value using the incorrect meta key of
In the other thread the person was updating the sub field inside a have_rows() loop and ACF was assuming the index of
0, which would be correct for the first row of a repeater.
There is likely a bug, I can’t fix bugs, this would have to be reported to the developers. I don’t use update_sub_field() as a general rule so it is only recently, that other topic, that brought it to my attention. My opinion when updating repeaters, or group fields, is to use a similar method to this, updating the entire repeater rather than a sub field. On the other hand, I almost never update fields from code.
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!