Support

Account

Home Forums ACF PRO get a repeater-field with an object-field in a repeater-field Reply To: get a repeater-field with an object-field in a repeater-field

  • You need to remove the nested setup_postdata() and wp_reset_postdata() and use some other method of referencing these nested posts. This includes using some other variable name for the post object besides $post.

    Here is your code with some modification

    
    <?php 
    if ( have_rows( 'repeater_field' ) ) :
      while ( have_rows( 'repeater_field' ) ) : the_row();
        $post_objects = get_sub_field( 'object_field' );
        if ( $post_objects ):
          foreach ( $post_objects as $post ): 
            setup_postdata( $post );
            $post_object = get_field( 'object_field' );
              if ( $post_object ):
                  if ( have_rows( 'repeater_field', $post_object->ID ) ) :
                    while ( have_rows( 'repeater_field', $post_object->ID ) ) : the_row();
                      the_sub_field( 'sub_field' );
                    endwhile;
                  endif;
              endif;
              
        endforeach;
        wp_reset_postdata();
      endif;
        
    endwhile;
    endif;
    ?>