Support

Account

Home Forums ACF PRO Targeting specific nested repeaters

Unread

Targeting specific nested repeaters

  • 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;

    }

Viewing 1 post (of 1 total)

The topic ‘Targeting specific nested repeaters’ is closed to new replies.