Home › Forums › Front-end Issues › Display Relationship Posts in Grid › Reply To: Display Relationship Posts in Grid
I’ve finally figured it out. This is what I used to be able to show my related posts on WooCommerce product pages:
<?php
$vendorposts = get_field('related_posts');
if( $vendorposts ): ?>
<div class="latest_post_holder boxes three_columns two_rows">
<ul>
<?php foreach( $vendorposts as $post): // variable must be called $post (IMPORTANT) ?>
<?php setup_postdata($post); ?>
<li>
<?php if ( has_post_thumbnail( $rp->ID ) ) : ?>
<?php echo get_the_post_thumbnail( $rp->ID, 'regular-posts' ); ?>
<?php else : ?>
<img src="<?php echo get_template_directory_uri(); ?>/img/no-image.png" alt="" />
<?php endif; ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
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.