Support

Account

Home Forums General Issues Using update_field to update repeter field nested in repeater field

Solved

Using update_field to update repeter field nested in repeater field

  • As in the topic title. In the first attachment you can see my ACF structure. There is repeater field nested in repeater field. Now what I need to do is to update field value using update_field function.

    To see how data structure looks like I have created page and populated it with data (look on second attachemnt) and then get_field and print_r the value to see the array structure:

    Array
    (
        [0] => Array
            (
                [werset] => Array
                    (
                        [0] => Array
                            (
                                [tekst] => First chapter - first verse
                            )
    
                        [1] => Array
                            (
                                [tekst] => First chapter - second verse
                            )
    
                    )
    
            )
    
        [1] => Array
            (
                [werset] => Array
                    (
                        [0] => Array
                            (
                                [tekst] => Second chapter - first verse
                            )
    
                    )
    
            )
    
    )

    Secondly I have did array with the same structure and when I`m using:

    update_field( $field_key, $value, $post_id );

    it generates error:

    Warning: Invalid argument supplied for foreach() in /home/wizjo/public_html/betezda.pl/wp-content/plugins/advanced-custom-fields/core/api.php on line 1369

    I think that the problem is with my $value array. What format should it be to update properly?

    • Elliot

    • October 29, 2013 at 5:39 pm

    Hi @studiowizjo

    The update_field function does not append any data, so you will have to run update_field on the entire repeater and override all the data. This is not efficient but currently, this function is very simple.

    The data must be in the same format as to which it is given to you. The easiest way is to look at the docs and see how the get_field function is used to load the entire repeater field value, then append a row to it, and then save it again.

    You can see that each row is an array where the keys are each sub_field name

    Does that help?

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

You must be logged in to reply to this topic.

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.