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);
}
}
Hi,
I attempted the solution above but it seems to be outputting the_field of the current post rather than the_field data of the related post.
Does this solution work when the current post and the related post are both assigned the same custom field?
I also attempted the solution posted below with the shortcode, which resulted in no output at all.
How do I display a custom field in another custom post type as a shortcode?