X

Display related posts by posts current author

Adding the first snippet to the functions.php of your wordpress theme will let you display 5 related posts by the current author. Add the second snippet into the single.php of your wordpress theme in the location you wish to display the related posts. This is a great little snippet from people over at wpbeginner.com.



Code Snippet:

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;
}


Code Snippet:


<?php echo get_related_author_posts(); ?>

Comments  Leave a Reply

  1. 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.

  2. How can I show only post of current author current author (sign in) in a multi author blog?

  3. How to Read HTML in Wordpress for Absolute Beginners March 12, 2014 at 1:04 pm

    […] Related Posts By Current Author snippet […]

  4. Dear Kevin,
    How can i add post date to each listed post

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!