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 = '
- ';
foreach ( $authors_posts as $authors_post ) {
$output .= '
- ' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . ' '; } $output .= '