Related posts by author

For displaying related posts by author somewhere in your WordPress website you can use the following function:

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

 if( $authors_posts && count( $authors_posts ) >= 1 ) :
 $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>' . apply_filters( 'the_excerpt', $authors_post->post_excerpt, $authors_post->ID ) . '</li>';
 $output .= '</ul>';
 else :
 $output = '<div class="error"><p>'. __( 'Nog geen artikelen geschreven...' ) .'</p></div>';
 return $output;


 /*add this hook where you need the related posts*/
 echo get_related_author_posts();

Tip! If you want to use posts from a custom post type, you need to specify this in get_posts() by adding: ‘post_type’ => ‘post-type-name’.


WordPress show author avatar

If you want to show the avatar of a WordPress author you can do this by:

First, get the author e-mail and put it in a variable:

<?php $user_email = get_the_author_meta('user_email'); ?>

And then, put this variable in the id_or_email parameter of the get_avatar(); function to distinguish which author you need, and echo the function out:

<?php echo get_avatar( $user_email, 80, $default, $alt ); ?>

More information about the get_avatar(); function:

Tip: I use the Worpress User Avatar plugin to upload a avatar picture to the author.