Support

Account

Home Forums Add-ons Repeater Field Add rows to repeater Reply To: Add rows to repeater

  • You’re code is not easy to follow, but I think that your issue is that you are attempting to use [] to assign values directly to the array as you get them. To build a nested array you need to build the sub array and then add it to the main array all at once.

    Here is a simple example

    
    // initialize the array to hold the repeater value
    $value = array();
    
    // main repeater
    while (have_rows('main_repeater')) {
      the_row();
      // start building this row from sub fields of the main repeater
      $row = array(
        // add fields of the main repeater
        'field_key' => get_sub_field('field_name')
      );
      // sub repeater
      if (have_rows('sub_repeater')) {
        // initialize the sub repeater array
        $sub_repeater = array();
        while(have_rows('sub_repeater')) {
          the_row();
          // add a row to sub repeater array
          $sub_repeater[] = array(
            // add fields from sub repeater
            'field_key' => get_sub_field('field_name')
          );
        } // end sub repeater while
        // add sub repeater to the current row
        $row['sub_field_repeater_key'] = $sub_repeater;
      } // end sub repeater if
      // add the new row to the main repeater
      $value[] = $row;
    } // end main repeater while