Support

Account

Home Forums Front-end Issues Can only get 1 post object to show in repeater field that contains 2 post object Reply To: Can only get 1 post object to show in repeater field that contains 2 post object

  • This is a common error/problem when running a custom query on a page. When you use wp_reset_postdata() or wp_reset_query() they do not reset the query to your query, they reset the query to the main WP query. This results in the second itteration of the have_rows loop to look at something that is not the post in your custom query. These are highly misunderstood functions.

    When running a custom query your nested loop for the rows cannot use setup_postdata(), and the reset function and you need to loop through the posts in another way.

    
    $post_object = get_sub_field('content');
    if ($post_object) {
      ?>
        <div>
          <h3><a href="<?php 
              echo get_permalink($post_object->ID); ?>"><?php 
              echo get_the_title($post_object->ID); ?></a></h3>
        </div>
      <?php 
    }