Home › Forums › Front-end Issues › Nested Post Object Fields › Reply To: Nested Post Object Fields
I’m going to try to help you by explaining what the problem with your code is. This comes up often because most people don’t understand how wp_reset_post_data() really works.
// this is inside the main WP query loop or "The Loop"
// some time later
$post_object = get_sub_field('pick_the_dates');
if( $post_object ):
$post = $post_object; setup_postdata( $post );
// some time later
if( $venue_object ):
$venue = $venue_object;
setup_postdata( $venue );
// some time later,
// this is the problem.
// wp_reset_post_data does not take any arguments
// this function, no matter how you call it will always
// reset post data to "The Main Query"
// once you do this, any reference to the post
// object returned by get_sub_field('pick_the_dates')
// will be looking at the post of the main query instead
// of what you think you are looking at
// in order to have multiple nestings you must use
// alternate means of getting values
// other than using setup_postdata and wp_reset_postdata
wp_reset_postdata( $venue );
// some time later
// this next line actually does nothing
// because it was already done above
wp_reset_postdata();
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.