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><!--/.meta-->
<div class="entry-text">
<?php the_content();?>
</div><!--/.entry-text-->
<div class="show-related-ricette">
<span class="icon-top-arrow"></span> Ricette correlate al corso
</div><!--/.show-related-ricette-->
<?php
$posts = get_field('ricette_correlate');
if( $posts ): ?>
<div class="related-ricette">
<div class="close"><span class="icon-close"></span></div>
<ul>
<?php foreach( $posts as $post ): setup_postdata($post); ?>
<li>
<a href="<?php echo get_permalink(); ?>"><?php echo get_the_title(); ?></a>
</li>
<?php endforeach; $the_query->reset_postdata(); ?>
</ul>
</div><!--/.related-ricette-->
<?php endif; ?>
<div class="cat-list">
<?php
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>';
}
?>
</div><!--/.cat-list-->
</div><!--/.entry-content-->
</div><!--/.item-corso-->
</div><!--/.col-->
<?php endwhile; ?>
</div><!--/.col-group-row-->
</div><!--/.listing-corsi-->
<?php endif; 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.