0

using the code below to show 4 related posts from author

<?php global $authordata, $post; ?>
<?php $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 4 ) ); ?>

<?php foreach ( $authors_posts as $authors_post ) { ?>

<div class="uk-width-medium-1-4">
<a href="<?php the_permalink($authors_post->ID) ?>">
<?php the_post_thumbnail($authors_post->ID); ?>
</a>
</div>

<?php } ?>

Problem is, permalinks work fine, but the thumbnail is on all 4 related links the same as the thumb on the post itself. Which is set as featured image on the post I want to set the related posts. Any suggestions? Thanks.

1 Answer 1

2

I think the problem may be that the_post_thumbnail() doesn't accept an ID as a parameter. Instead you should use get_the_post_thumbnail() which does accept an ID as a parameter:

 <?php echo get_the_post_thumbnail($authors_post->ID); ?>
1
  • I tried it before but only as <?php get_the_post_thumbnail($authors_post->ID); ?> and didn't realise I needed to echo this. Thanks Stephen, works like a charm!
    – AKNL
    Commented Apr 21, 2016 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.