Home › Forums › General Issues › Get a repeater of post_objects data from within a post_object › Reply To: Get a repeater of post_objects data from within a post_object
The main issue is that you cannot nest setup_postdata() and wp_reset_postdata() the way you have done. The reason is that wp_reset_postdata() does not reset to the previous post in the nesting, it always resets to the post of “The Loop” (the main WP loop showing the post for the current page).
You need to get values from other posts in some other way than using this method
You are also using get_sub_field() without having a have_rows() loop. You cannot get the repeater using get_field() and then use get_sub_field() to get a value from the repeater rows. You either need to use the array returned by get_field() $row['lesson_individual']
or you need to use a have_rows() loop.
The next issue is that your using $post_object for multiple uses and the second one is overwriting the value of the first use.
$post_object = get_field('parent_course');
// then in the nested loop
$post_object = get_sub_field('lesson_individual');
And then there is an issue using the_title(). this function always echos the title and it cannot be used in this syntax
$lesson_title = the_title();
removing the issues results in something like:
$post_object = get_field('parent_course');
if ($post_object) {
if (have_rows('lesson_select', $post_object->ID)) {
while (have_rows('lesson_select', $post_object->ID)) {
the_row();
$lesson_object = get_sub_field('lesson_individual');
$lesson_title = get_the_title($lesson_object->ID);
echo '<p>',$lesson_title,'</p>';
}
}
}
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.