I have a repeater with multiple nested repeaters that I am trying to populate programmatically via an Ajax call that creates a post in a custom post type. I have been able to successfully add and populate the text field within the parent repeater and update the nested repeaters, however, my problem is trying to differentiate between the nested repeaters. Right now, I have it set up to stop adding values to the nested repeater based on an incrementing variable that, however, this is causing a 502 error to be returned and it’s adding all of the values to all of the nested repeater fields. When not adding rows to the nested repeater, it prints out the results properly. I’m using AFC Pro v5.5.3 and WP 4.6.1 Here is my code:
$insert = wp_insert_post($page);
if($insert) {
//Update Repeater Field
$field_key = “field_58de91d18f6cf”;
//update_field( $field_key, $sectionArray, $insert );
foreach( $sections as $section ) :
$questionTitle = $section->questionTitle;
$sectionTitle = $section->sectionTitle;
$sectionID = $section->sectionID;
$isChecked = $section->isChecked;
$value = $section->value;
//$results .= $value.’ ‘;
if($prev_section != $sectionTitle) {
//update_sub_field( array(‘sections’, $insert, ‘section_title’), $sectionTitle);
$row = array(
‘section_title’ => $sectionTitle,
);
$i = add_row($field_key, $row, $insert);
$prev_section = $sectionTitle;
}
endforeach;
if( have_rows(‘sections’, $insert) ):
$qCount = 1;
$prevQ = ”;
$prevSection = ”;
// loop through the rows of data
while ( have_rows(‘sections’, $insert) ) : the_row();
// display a sub field value
$section_title .= get_sub_field(‘section_title’).’ ‘;
//$results .= ‘Has Sections’;
foreach( $sections as $section ) :
$questionTitle = $section->questionTitle;
$sectionTitle = $section->sectionTitle;
$sectionID = $section->sectionID;
$isChecked = $section->isChecked;
$value = $section->value;
$questionID = $section->questionID;
if($prevSection != $sectionTitle) {
$qCount = 1;
$prevSection = $sectionTitle;
}
if($prevQ != $questionTitle) {
$prevQ == $questionTitle;
if($qCount == $questionID) {
$row = array(
‘question’ => $questionTitle
);
//$results .= $qCount.’ ‘.$questionTitle.’ ————————————————- ‘;
$j = add_sub_row(‘field_58de92398f6d1’, $row, $insert);
++$qCount;
}
}
endforeach;
endwhile;
else :
// no rows found
$results .= ‘No Sections’;
endif;
}
You must be logged in to reply to this topic.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc
— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.