Home › Forums › Backend Issues (wp-admin) › Using update_field() saves Repeater field differently › Reply To: Using update_field() saves Repeater field differently
The only think that I can think of is that get_field()
is returning an array and the sub fields returned are by field name and you should be using the field keys for each sub field when updating.
You don’t need to inspect _postmeta table to get the field keys. They are available when editing a field group under “screen options”
What you’ll need to do is convert all the names to field keys
$new_post_id = wp_insert_post($new_post);
$field_key = "field_53e4ed1e04b91";
$sub_field_list = array(
'field_name_1' => 'field_key_1',
'field_name_2' => 'field_key_2',
// etc...
)
$value = get_field('downloads',$id);
$new_value = array();
if (count($value)) {
foreach ($value as $row=> $sub_fields) {
$new_value[$row] = array();
foreach ($sub_fields as $sub_field_name => $sub_field_value) {
$new_value[$row][$sub_field_list[$sub_field_name]] = $sub_field_value;
}
}
}
update_field( $field_key, $new_value, $new_post_id );
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.