Support

Account

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

Solved

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):

    if($sum>$icelp4)
            {
                $dif=$sum-$icelp4;
                if($cp4>=$cr4)
                {
                    remove_action( 'save_post', 'investment_save' );
    
                    $cp=$cp4-$dif;
    
                    $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 );
                }else
                {
                    $cr=$cr4-$dif;
    
                }
            }

    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()?

    Thanks

    edit: I saw this thread http://support.advancedcustomfields.com/forums/topic/can-you-update-a-row-in-a-repeater/ 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 );
    
    $counter=$counter+1;

    and then keep looping it around

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

The topic ‘Updating a Repeater field instead of adding a new row’ is closed to new replies.