WordPress Snippets at WPcustoms

Show related posts by current post author

Author related posts snippet for a multi-author site. This snippet shows latest 5 posts published by the current post’s author. Feel free to modify the get_posts query arguments.


/**
 * Snippet Name: Show related posts by current post author
 * Snippet URL: https://wpcustoms.net/snippets/show-related-posts-by-current-post-author/
 */
  // usage: echo wpc_get_related_author_posts();
function wpc_get_related_author_posts() {
    global $authordata, $post;
    $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
    $output = '';
    return $output;
}