Hi there, I’m trying to set a setup_postdata($post) inside another setup_postdata($post) and after closing the last wp_reset_postdata(), the first loop doesn’t work anymore, any hint? This is because inside the first loop I have to get some data from another relationship field.
<?php $negatives = get_field( "collections_single_work"); ?>
<?php if( $negatives ): ?>
<?php foreach( $negatives as $post ): ?>
<?php setup_postdata($post); ?>
here goes some coding
<?php $collectionsizes = get_field( "collection_edition_size"); ?>
<?php if( $collectionsizes ): ?>
<?php foreach( $collectionsizes as $post ): ?>
<?php setup_postdata($post); ?>
here goes some coding
<?php wp_reset_postdata(); endforeach; ?>
<?php endif; ?>
here goes some coding which is part of the first loop and is not reading the previous setup_postdata($post)
<?php wp_reset_postdata(); endforeach; ?>
<?php endif; ?>
Finally, I resolved it like this, on the second query inside the loop
<?php $negatives = get_field( "collections_single_work"); ?>
<?php if( $negatives ): ?>
<?php foreach( $negatives as $post ): ?>
<?php setup_postdata($post); ?>
here goes some coding
<?php $related_posts = get_field('collection_edition_size');
if ($related_posts) {
foreach ($related_posts as $related_post) {
?>
<?php if( get_field('size_of_the_negative', $related_post->ID) == '4x5'): ?>
here goes some coding
<?php
}
} ?>
here goes some coding which is part of the first loop
<?php wp_reset_postdata(); endforeach; ?>
<?php endif; ?>