@shaun Thanks for sharing your code. This helped a lot – but I am facing the issue with a repeater field. I believe this is not supported with your solution. Do you have a solution for repeater fields as well?
I know that the value of repeater fields are stored like this pattern in the postmeta database:
repeaterfieldname_0_fieldname
Now, when I save my repeater field I get this form in the $_POST[‘acf’] variable. I believe I can not make a connecttion to this structure (repeaterfieldname_0_fieldname), can I? My repeater field is named “product_options”, and the fields are named “component”, “text”, “price”.
array(2) {
["field_5aa23edb20eb5"]=> array(2) {
["5aa24c5eafcd0"]=> array(3) {
["field_5aa23f0020eb6"]=> string(3) "abc"
["field_5aa23f0920eb7"]=> string(4) "abc2"
["field_5aa23f1420eb8"]=> string(2) "12"
}
["acfcloneindex"]=> array(3) {
["field_5aa23f0020eb6"]=> string(0) ""
["field_5aa23f0920eb7"]=> string(0) ""
["field_5aa23f1420eb8"]=> string(0) ""
}
}
}
So basically field_5aa23f0020eb6 is “component” etc. Maybe @elliot has an idea?
Edit:
It does work like this, but maybe there is another, more convenient, solution?
foreach ( $fields as $key => $val ) {
if (is_array($val)) {
foreach ($val as $k => $v) {
foreach ($v as $fKey => $fValue) {
if ($fKey !== 'acfcloneindex') {
$i = add_row($k, $fValue, $variation_id);
}
}
}
} else {
update_field( $key, $val, $variation_id );
}
}