Problem passing ID to the_post_thumbnail()
-
Pretty sure I’m doing something wrong here, so if anyone can point me in the right direction I’d appreciate it. Basically, I’m trying to loop through posts and display a featured image called secondary-image (I’m also using Advanced Custom Fields and YARPP). The code below seems to be ignoring $related_story->ID in the_post_thumbnail(). I can echo the ID, but just can’t pass it to MultiPostThumbnails::the_post_thumbnail(). If I change it to NULL, it works, but displays the secondary-image that’s attached to the current post (this code is in single.php inside the loop). The post titles and permalinks work, but the thumbnails don’t. Any ideas? Sorry if this is really confusing. Perhaps I need to explain it better.
while ( has_sub_field('choose_stories') ) { $related_story = get_sub_field('custom_story'); ?> <a href="<?php echo get_permalink($related_story->ID); ?>"> <?php if ( MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image', $related_story->ID) ) { ?> <?php echo MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image', $related_story->ID); ?> <?php } else { ?> <img src="<?php bloginfo('template_directory'); ?>/images/m.png" alt="<?php echo $related_story->post_title; ?>"> <?php } ?> </a> <?php }
https://www.ads-software.com/plugins/multiple-post-thumbnails/
- The topic ‘Problem passing ID to the_post_thumbnail()’ is closed to new replies.