Home Forums Add-ons Repeater Field Post Object inside Repeater only displaying first row Reply To: Post Object inside Repeater only displaying first row

  • Your code would be easier to read if you used code tags.

    Below is your code with code tags and comments explaining what the likely problem is.

      // there is a main query that happens before this code is run
      // this is a new custom query, not the main query
      $args = array('post_type' => 'menu', 'posts_per_page' => -1, 'orderby'=>'menu_order','order'=>'ASC');
      $menus = new WP_Query($args);
      if ($menus->have_posts() ):
        echo '<div id="the_menus">';
        while ($menus->have_posts()): $menus->the_post();
          $menu_name = get_the_title();
          $menu_slug = $post->post_name;
          echo '<div class="menu '.$menu_slug.'">';
          if ( have_rows('appetizer_items') ):
            // we need a way to restore the inner loop post
            // this cannot be done with wp_reset_postdata()
            // this will store the current $menus post
            // so we can get it back later
            $temp_post = $post;
            echo '<h3>Appetizers</h3>';
            echo '<div class="divider">'.$divider_dark.'</div>';
            while ( have_rows('appetizer_items') ): the_row();
              $appetizer_item = get_sub_field('appetizer_item');
              $post = $appetizer_item;
              setup_postdata( $post );
              $title = get_the_title();
              echo '<h4>'.$title.'</h4>';
              // this next line is resetting post data 
              // to the main query post
              // not to your custom query post
              // you need to remove this statement
              // wp_reset_postdata();
              // and we don't need to restore the
              // $menus post until after the end
              // of the have_rows() loop
          // end of have rows
          // reset the inner loop post
          setup_postdata( $temp_post );
          echo '</div>';
        echo '</div>';
        // reseat the main query postdata