Home › Forums › ACF PRO › Using relationship reverse query in a custom loop › Reply To: Using relationship reverse query in a custom loop
I’m guessing here because I cannot see how the loops over the posts are done. You are probably having an issue do to nested loops. There is the first loop “The Loop” which is the main loop done by WP, then you have a second loop over the “instructors” nested in this loop and finally you have a “trip” loop nested in that loop. Generally at the end of a nested query loop a the function wp_reset_postdata() is called to reset the post to the previous loop, but when working with nested loops this breaks the previous loop. The reason for this is the wp_reset_postdata() always resets the post to the primary WP loop and not any intermediate loops.
// primary WP loop
while (have_posts) {
// secondary loop
while ($secondary_query->have_posts()) {
// tertiary loop
while ($tertiary_query->have_posts()) {
}
// this call will not reset post data to post of $secondary query
// this function always resets post data to primary loop post
wp_reset_postdata();
// in this case instead of this function you must call
$secondary_query->wp_reset_postdata();
}
wp_reset_postdata(); // resets to primary loop post
}
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.