Just a general question seeing if anyone can help. I want to use the relationship field to link to a custom post type then display in a loop for the page all posts related to it.
I.E. Let’s Say Games CPT with a page for World of Warcraft I want to then link all Posts to said game and display them in a loop on the game page.
So what I am trying to figure out is if this loop would do that
<?php
$posts = get_field('relationship_field_name');
if( $posts ): ?>
<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>
<span>Custom field from $post: <?php the_field('author', $p->ID); ?></span>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>