0
votes

I have a related posts by author function using this code:

function get_related_author_posts() {
global $authordata, $post;

$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 10 ) );

$output = '<div class="block">';
foreach ( $authors_posts as $authors_post ) {
    $output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
}
$output .= '</div>';

return $output; }

To output I use the following code inside the loop of my single.php file:

 <?php echo get_related_author_posts(); ?>

Currently the function it displays only post titles as links.

How should look this wp code in order to display thumbnails for this related posts by author function?

1

1 Answers

0
votes

Try:

foreach ( $authors_posts as $authors_post ) {
  $output .= get_the_post_thumbnail($authors_post->ID);
  $output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
}
$output .= '</div>';

check get_the_post_thumbnail for more information like image size and attributes like extra classes.
Let me know if you need more help.