Home Forums ACF PRO Relationship Field


Relationship Field

  • 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

    $posts = get_field('relationship_field_name');
    if( $posts ): ?>
    	<?php foreach( $posts as $p ): // variable must NOT be called $post (IMPORTANT) ?>
    	    	<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>
    	<?php endforeach; ?>
    <?php endif; ?>
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Relationship Field’ is closed to new replies.