Support

Account

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

  • John, I actually got this working now.

    // start building this row from sub fields of the main repeater
        while ( have_rows( 'boat_lines', 'option' ) ) : the_row();        
            $line_value = get_sub_field('line_name');
            $line_name = get_sub_field('label');
            $line_image = get_sub_field('image');
            
            $boat_line_repeater_rows = array(
                // add fields of the main repeater
                'field_64dfd8bf4bc3f' => $line_value,
                'field_64dfd8bf4bc40' => $line_name,
                'field_64dfd8bf4bc41' => $line_image,
            );   
    
            // sub repeater        
            if ( have_rows('model') ) {
                // initialize the sub repeater array
                $boat_line_model_repeater_rows = array();
    
                while( have_rows('model') ) : the_row();
                    // Get sub value.
                    $model_value = get_sub_field('value');
                    $model_name = get_sub_field('name');  
                    $model_image = get_sub_field('image');  
                    
                    // add a row to sub repeater array
                    $boat_line_model_repeater_rows[] = array(
                        // add fields from sub repeater
                        'field_64dfd8bf4bc43' => $model_value,
                        'field_64dfd8bf4bc44' => $model_name,
                        'field_64dfd8bf4bc45' => $model_image
                    );
    
                endwhile; // end sub repeater while
    
                // add sub repeater to the current row
                $boat_line_repeater_rows['field_64dfd8bf4bc42'] = $boat_line_model_repeater_rows;
            } // end sub repeater if
    
            // add the new row to the main repeater
            $boat_line_rows[] = array(
                // field key => value pairs for each sub field            
                'field_64dfd8bf4bc3e' => array(
                    $boat_line_repeater_rows
                )
                // next row in nested repeater
            );
    
        endwhile; // end main repeater while