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
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.