Home Forums Add-ons Repeater Field Save Field In Repeater Row On Options Page


Save Field In Repeater Row On Options Page

  • Hi there,

    I’m trying to get a field from a repeater row, and then save a field inside the repeater row every time a page is loaded. The field I’m trying to save is a number field inside a repeater and the repeater is on an options page rather than associated with a post.

    To do this I made the following:

           $right_margin =  $specific_row['sponsor_right_margin_image' ];
           $size = 'full';
           if($right_margin) {
              echo '<div class="rightmargin">' . wp_get_attachment_image( $right_margin, $size ) . '</div>';
              $No_Of_Times_Margins_Loaded =  $specific_row['sponsor_no_of_times_margins_loaded' ];
              update_sub_row( array('sponsors', 1, 'no_of_times_margins_loaded'), 1, $No_Of_Times_Margins_Loaded );

    However, this doesn’t seem to work. Am I using the right function or should I be using update_sub_field?

  • You need to supply the post ID

    update_sub_row( array('sponsors', 1, 'no_of_times_margins_loaded'), 1, $No_Of_Times_Margins_Loaded, 'options' );

  • Hi John

    I have tried your solution but it didn’t seem to work. Would there be any obvious reason why not?


  • Going to be honest, I’ve never used the function. The only thing that I can think of is that repeater/row/sub field does not already exist where you are attempting to updated it.

    If this is the case then you should use field keys rather than field names.

  • Would it make a difference if I’m using the above code in a page template rather than in the functions.php file?

  • It should not as long as you specify the post ID (in this case options or whatever you options page post ID is set to) when updating the fields there.

  • I have now solved this. In the end, it was a combination of using the wrong function and not using the keys as John mentioned. The final line ended up being

    update_sub_field(array('field_6064394540d2c', 1, 'field_609d2cad7f0b2'), $number, 'options');

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

You must be logged in to reply to this topic.