Home › Forums › ACF PRO › Relationship Problem on Archive page › Reply To: Relationship Problem on Archive page
<?php $posts=get_field( 'ricette_correlate'); if( $posts ): ?>
<div class="related-ricette">
<ul>
<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>">
<?php echo get_the_title( $p->ID ); ?></a>
</li>
<?php endforeach; ?> </ul>
</div>
<!--/.related-ricette-->
<?php endif; ?>
this is inside homepage (created with a custom page tpl, inside the post-type query).
Complete code of custom query:
<?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 $p ): // variable must NOT be called $post (IMPORTANT) ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
</li>
<?php endforeach; ?>
</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.