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
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.