Home Forums Add-ons Repeater Field Updating a Repeater field instead of adding a new row


Updating a Repeater field instead of adding a new row

  • I’m using Advanced custom field plugin and I’m using an extension called a “Repeater”, I’ve figured out how to programatically add lines to the repeater, however I’m looking to instead modify the current values of a row instead of adding one. Here is the code that lets me add a row(But it should modify the row instead of adding it):

                    remove_action( 'save_post', 'investment_save' );
                    $field_key = "datos_especificos";
                    $value = get_field($field_key, $post_id);
                    $value[] = array("fecha" => $fech4, 
                                     "saldo" => $sal14,
                                     "inversion_en_el_periodo" => $ielp4,
                                     "interes_causado_en_el_periodo" => $icelp4,
                                     "cantidad_pagada" => $cp,
                                     "cantidad_reinvertida" => $cr4,
                                     "saldo_final" => $sf4);
                    update_field( $field_key, $value, $post_id );

    I’m using ACF 4.0 so I can’t use update_sub_field(); Does anyone out there know how to do this with update_field()?


    edit: I saw this thread but It says I can delete the array from the code and that wont add the new row, but how do I update it? I’m confused.

  • I solved it, I just had to add a counter in the array( value[“here”] ), so that if, lets say, I wanna modify the information of the 1st row, then id put something like this:

    $counter = 0;
    $value[$counter] = array("fecha" => $fech4, 
    									 "saldo" => $sal14,
    									 "inversion_en_el_periodo" => $ielp4,
    									 "interes_causado_en_el_periodo" => $icelp4,
    									 "cantidad_pagada" => $cp4,
    									 "cantidad_reinvertida" => $cr,
    									 "saldo_final" => $sf4,);
    					update_field( $field_key, $value, $post_id );

    and then keep looping it around

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

You must be logged in to reply to this topic.