Are you looking for a way to display related posts by the current author? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display related posts by posts current author.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
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' => 5 ) ); $output = '<ul>'; foreach ( $authors_posts as $authors_post ) { $output .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>'; } $output .= '</ul>'; return $output; }
Add this code snippet to the single.php file of your WordPress theme to display related posts.
<?php echo get_related_author_posts(); ?>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: how to transfer WordPress from local server to a live site and 12 best blogging platforms for beginners.
Hi there!
How can I show posts from a specific Custom Post Type related to post Author?
I tried this but didn’t worked. It returned all posts from all site members instead.
$authors_posts = get_posts( array( ‘author’ => $authordata->ID, ‘post__not_in’ => array( $post->ID ), ‘post_type’ => ‘membros_documentos’, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘posts_per_page’ => ‘-1’ ) );
Please help.
Thank you.
How can I show only post of current author current author (sign in) in a multi author blog?
[…] Related Posts By Current Author snippet […]
Dear Kevin,
How can i add post date to each listed post