Support

Account

Home Forums ACF PRO Update a repeater field through update_field

Solved

Update a repeater field through update_field

  • Hi, I created a custom form in the frontend in order to introduce data to a repeater field, avoiding enter in the wp admin interface.

    This form asks for the 4 fields that we need to fill the data required for the repeater row.

    On submit, the function that updates the repeater field is triggered, and ideally the post meta information should be updated accordingly.

    OK, the function is executed and what I obtain is a new register on the post_meta table, where the meta_key is the field key and the meta_value is a serialized array with all the info that contains the array that I use in the variable.

    Something like:
    meta_key: field_58e6a85137e3f
    meta_value: a:1:{i:0;a:4: s:19:”field_58e6a87137e40″;s:8:”20230726″;s:19:”field_58e6a8d737e41″;s:4:”mafs”;s:19:”field_58e6a90837e42″;s:9:”anotacion”;s:19:”field_58e6a9c337e43″;s:4:”test”;}}

    So, it’s evident that I’m doing something wrong.
    Does anyone has any idea on what’s happening ?

    
    if ('ENVIAR' === ($_POST['enviar-a-crm'] ?? false)) {
                $$evaluate = FALSE;
                if ( ($_POST['id-socio']) != '' ) {
                    //array con los datos
                    $array_data = array(
                        array(
                            'field_58e6a87137e40'   => $_POST['fecha'], //Fecha tipo 20130830
                            'field_58e6a8d737e41'   => $_POST['autor'], //Autor
                            'field_58e6a90837e42'   => $_POST['tipo'], //Tipo
                            'field_58e6a9c337e43'   => $_POST['descripcion'], //Descripcion
                        )
                    );
                    $evaluate = update_field('field_58e6a85137e3f', $array_data, $_POST['id-socio']);
                    if ( $evaluate ) {
                        echo 'EXECUTED';
                    } else {
                        echo 'IS FALSE';
                    }
                } else {
                    echo 'ERROR EN DATOS';
                }
    
                echo '<pre>';
                var_dump($evaluate);
                echo '<br/>------<br/>';
                var_dump($_POST);
                echo '</pre>';
            }
    
  • is ‘field_58e6a85137e3f’ the field key of your repeater?

    Is the repeater nested in any other field? (repeater, group, flex)

    You should also use add_row(), using update_field() the way you are using it will delete any existing rows.

  • Sorry, I selected the answer as solved and it’s not.

    Dear John, I confirm that the field key is the repeater one, and that the repeater is not nested in any other field.

    I firstly use add_row(), and nothing happens.

    I checked if acf was active in the template where I have this problem and it was…

    I finally solved the issue, using native wp functions, and building the repeater registers in post_meta with add_postmeta or update_postmeta, it has been a lot more work, but I was in a hurry and needed to solve it quickly.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.