Hi, and first off all, thanks for help.
I have to following code to display related posts from one custom post type to another with ACF Relationships.
what i want to know, is it possible and how can i rewrite the code, to output any custom field of the related post that i have selected with the relationship field?
<?php
$posts = get_field('product_id');
if( $posts ): ?>
<ul>
<?php foreach( $posts as $p ): ?>
<li>
<a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo get_the_title( $p->ID ); ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
like i do here, is:
echo get_permalink( $p->ID );
i want to echo:
the_field('field_name')
regards,
Axel
<?php
$posts = get_field('product_id');
if( $posts ) {
foreach ($posts as $p) {
// this goes where you want the fields from the related post
the_field('field_name', $p->id);
}
}