I have a 'Match' CPT to create posts for each game played by a football team. These posts display details of the opposition team by pulling through information from the appropriate post from another CPT - 'Clubs'. The one bit I've not been able to work out is how to get the thumbnail.
The current code is:
<h2 class="match-team"> <span class="match-badge"> <?php $opposition = get_field('club'); if($opposition): ?> <img src="https://www.MYDOMAIN.co.uk/images/club/<?php echo $opposition->post_name; ?>.jpg" class="match-badge-img"> </span> <a class="match-name" href="/clubs/<?php echo $opposition->post_name; ?>/" > <span> <?php echo $opposition->post_title;?> </span> </a> <?php endif; ?> <span class="match-score"><?php the_field('opposition_goals'); ?></span> </h2>
The current img src does work IF the club has a unique image that has been uploaded i.e. club 1 has an image or club 13 has an image. But this is not true of all clubs, e.g. club 2 doesn't have an image. Therefore, this returns a broken image link.
Clubs without an image have a generic placeholder as their featured image, so the solution I'm aiming for is to change the img src path so that it pulls in that featured image. I've used this, but to no effect:
<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($opposition->post_name) ); ?><?php echo get_the_post_thumbnail($opposition->post_name); ?>" class="match-badge-img">
<?php echo $opposition->the_post_thumbnail('medium', array( 'class' => 'match-badge-img' ) ); ?>
But neither pull through the appropriate thumbnail, which suggests I've gone wrong with something pretty fundamental. Can
$opposition-> be used in this context?