I followed this guide:
https://www.advancedcustomfields.com/resources/querying-relationship-fields/
and all work fine.
I’ve a only problem with correct image in both directions. I’ll explain with terms of example link (doctors+locations):
In this code, in single-doctor.php, show list of locations :
<?php
$locations = get_field('location');
?>
<?php if( $locations ): ?>
<ul>
<?php foreach( $locations as $location ): ?>
<li>
<a href="<?php echo get_permalink( $location->ID ); ?>">
<?php echo get_the_title( $location->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
but I want to show also thumbnail image of locations. I add this:
<img src="<?php echo the_post_thumbnail_url( $location->ID ); ?>">
But it not work, and show the image of doctor (staying in the terms of the example)
The same thing in the other way: the thmbnail of doctor in single-location.php.
Help me! 🙂
Well..
I think you need to use other function. https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/
Something like this:
<img src="<?php echo get_the_post_thumbnail_url( $location->ID, 'thumbnail' ) ?>" />