Hi there,
I am using ACF to take values from a Formidable Pro form and add them to the correct fields on various pieces of content. Everything works great, except for one area.
One of my CPTs has a repeater field with a nested repeater relationship. You can see the array here:
Array ( [0] => Array ( [field_5588df159646d] => 1 [field_5589b19fa216e] => 1437044400 [field_5589b1cfa216f] => 1437048000 [field_5588de839646c] => Array ( [0] => 621 ) [field_5588de3c9646b] => 15 [field_5588e147d5609] => Array ( [0] => 725 [1] => 728 [2] => 729 ) ) [1] => Array ( [field_5588df159646d] => 5 [field_5589b19fa216e] => 1437078600 [field_5589b1cfa216f] => 1437084000 [field_5588de839646c] => [field_5588de3c9646b] => 15 [field_5588e147d5609] => Array ( [0] => 736 ) ) )
I need to add the new post to that relationship field and am doing so with the following code:
if(isset($_POST['classes']) && is_array($_POST['classes'])){
$studentClasses = $_POST['classes'];
foreach($studentClasses as $class){
$classSesh = array();
$class = explode('-', $class);
$session = $class[1];
$class = $class[0];
$class = get_post($class);
$classSesh = get_field('field_5588de169646a', $class->ID, false, false);
$classSesh[$session]['field_5588e147d5609'][] = strval($student_id);
update_field( 'field_5588de169646a', $classSesh, $class->ID);
unset($classSesh);
}
}
The problem is in field field_5589b19fa216e
and field_5589b1cfa216f
. These are timestamps that I do not need to touch. Without fail these are erased. I know this is not happening at the point that I am add the next row, the var_dump you see above is AFTER that row was added. However as soon as update_field is run, the student is added correctly, but other fields are erased.
Any advice would be appreciated!
Aris
I’ve ended up using get_post_meta
and update_post_meta
instead. Would love to know if this is a bug or not.
Hi @teama,
Thanks for the post.
I do not really think this is a bug, for sub_fields within a Repeater or a Flexible content field, you will need to make use of the update_sub_field() function instead of the update_field() function.
This function makes it possible to target the specific row and the parent field.
The topic ‘Odd update_field() error’ is closed to new replies.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.