Support

Account

Home Forums Add-ons Repeater Field Problema withe repeater item Reply To: Problema withe repeater item

  • I’ve pared down your code to the important bits to explain where the problem is. Hope it helps

    
    <?php
      // there is already a query running, the main query
      
      // this is a nested secondary query
      $the_query = new WP_Query(array(
          // .. your query here
      ));
      while( $the_query->have_posts() ) : $the_query->the_post();
        // .. do some stuff
        if( have_rows('bloco') ): 
          while ( have_rows('bloco') ) : 
            the_row();
            $post_objects = get_sub_field('artigos');
            if( $post_objects ): 
            
              // temporarily hold the post from your secondary query
              // see comment below about problem doing wp_reset_postdata();
              $temp_post = $post;
              
              foreach( $post_objects as $post): 
                setup_postdata($post); 
                // ... do some stuff
              endforeach;
              
              // you should do a wp_reset_postdata() here
              // however, if you do that you will reset post data
              // to the main query and not your secondary nested query
              // so get the value we stored above here
              $post = $temp_post;
              
            endif; //if( $post_objects ): foreach( $post_objects as $post): setup_postdata($post);
          endwhile;
        endif; //<?php if( have_rows('bloco') ): while ( have_rows('bloco') ) : the_row();
      endwhile; // end of the secondary query loop
      
      // this resets post data to main query
      wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
    ?>