Home Forums ACF PRO Relationship Problem on Archive page Reply To: Relationship Problem on Archive page

  • Hi,

    Okay.. So first off. I don’t think this can be called an issue of ACF as it’s more about what WordPress consider is the current global post or query. What you want to do is basically nested custom queries.

    Could you give this code a try? If you notice I do use $post for the foreach loop along with setup_postdata but instead of calling wp_reset_postdata() I call a function on the custom query itself to restore that in particular.

    <?php $args = array(
    	'post_type' => 'corsi',
    	'posts_per_page' => 6
    $the_query = new WP_Query( $args);
    // The Loop
    if ( $the_query->have_posts() ) : ?>
    <div class="listing-corsi">
    	<div class="col-group-row">
    		<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<div class="col one-third m-1-2 s-1-1">
    			<div class="item-corso" data-mh="grp-item-corso">
    				<figure class="bwWrapper main-thumb"><?php the_post_thumbnail('t630x364');?></figure>
    				<div class="entry-content">
    					<h2 class="entry-title"><?php the_title();?></h2>
    					<div class="meta">
    						<div class="date"><?php the_field('data_corso');?> / <?php the_field('orario_corso');?></div>
    					<div class="entry-text">
    						<?php the_content();?>
    					<div class="show-related-ricette">
    						<span class="icon-top-arrow"></span> Ricette correlate al corso
    					$posts = get_field('ricette_correlate');
    					if( $posts ): ?>
    					<div class="related-ricette">
    						<div class="close"><span class="icon-close"></span></div>
    						<?php foreach( $posts as $post ): setup_postdata($post); ?>
    					            <a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a>
    					  	<?php endforeach; $the_query->reset_postdata(); ?>
    					<?php endif; ?>
    					<div class="cat-list">
    						global $post;
    						$terms = wp_get_post_terms( $post->ID , 'tipologia_di_cucina' );
    						if ( $terms ){
    						    echo '<ul>';
    						    foreach ( $terms as $term ) {
    						      echo '<li><a href="'.get_term_link( $term ).'">' . $term->name . '</a></li>';
    						    echo '</ul>';
    		<?php endwhile; ?>
    <?php endif; wp_reset_postdata(); ?>