Home Forums General Issues Correct image relationship field


Correct image relationship field

  • I followed this guide:

    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 :

    $locations = get_field('location');
    <?php if( $locations ): ?>
    <?php foreach( $locations as $location ): ?>
    <a href="<?php echo get_permalink( $location->ID ); ?>">
    <?php echo get_the_title( $location->ID ); ?>
    <?php endforeach; ?>
    <?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.

    Something like this:

    <img src="<?php echo get_the_post_thumbnail_url( $location->ID, 'thumbnail' ) ?>" />
  • Yes, it works !

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Correct image relationship field’ is closed to new replies.