Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Display Related Posts by Same Author in WordPress

If you run a multi-author blog like ours, then you know how important it is to showcase each writer’s work effectively.

One way we’ve found to do this is by displaying related posts by the same author at the end of each article. This approach not only helps readers find more of what they like but also gives each author more visibility on your site.

In this article, we’ll show you how to display related posts by the same author in WordPress.

Displaying related posts by same author in WordPress

Why Display Related Posts by Author in WordPress?

By adding related posts in WordPress, you can help visitors find new content, keep them engaged, and increase pageviews while reducing the bounce rate.

However, if you run a multi-author WordPress blog, then visitors may want to read more posts by a specific author. If you show posts written by the same author, you can keep visitors on your site for longer and improve the reader experience.

Related posts by author displayed manually in WordPress

That said, let’s see how you can display related posts by the same author in WordPress.

Displaying Posts by the Same Author in WordPress (Easy Method)

The easiest way to show a list of related posts by the same author is by adding custom code to your WordPress site. We have tried finding plugins for this purpose, but the ones that we found are way too outdated.

Sometimes, guides will tell you to add custom code by editing your site’s functions.php file. However, we don’t recommend this method as even a small mistake or typo in the code can cause common WordPress errors or even break your site completely.

That’s where WPCode comes in.

WPCode is the best code snippets plugin that allows you to safely add custom PHP, CSS, HTML, and more to your WordPress website. You can also update your WordPress theme without losing your customization.

Besides displaying related posts by the same author, WPCode lets you add custom code to show random posts, exclude sticky posts from the post loop, and more.

First, you need to install and activate the free WPCode plugin. For more instructions, please see our beginner’s guide on how to install a WordPress plugin.

Upon activation, go to Code Snippets » + Add Snippet.

Adding custom code to a WordPress blog or website

Here, you will see all the ready-made snippets you can add to your website.

To create a snippet, simply hover over ‘Add Your Custom Code’ and then select ‘Use snippet’.

Displaying related posts using custom code and WPCode

This will take you to the ‘Create Custom Snippet’ page, where you can start by typing a name for your code snippet. This is just for your reference, so you can use anything you want.

After that, open the ‘Code Type’ dropdown and select ‘PHP Snippet’.

How to display related posts by same author using WPCode

You can now go ahead and paste the following snippet into the code editor:

function wpb_related_author_posts($content) {
    if (is_single()) {
        global $authordata, $post;
        
        // Fetch the author's display name
        $author_name = get_the_author_meta('display_name', $authordata->ID);
        
        // Insert the author's name into the string
        $content .= '<h4>Similar Posts by ' . $author_name . ':</h4> ';
      
        $authors_posts = get_posts(array(
            'author' => $authordata->ID,
            'post__not_in' => array($post->ID),
            'posts_per_page' => 5
        ));
      
        $content .= '<ul>';
        foreach ($authors_posts as $authors_post) {
            $content .= '<li><a href="' . get_permalink($authors_post->ID) . '">' . apply_filters('the_title', $authors_post->post_title, $authors_post->ID) . '</a></li>';
        }
        $content .= '</ul>';
      
        return $content;
    } else {
        return $content;
    }
}

add_filter('the_content', 'wpb_related_author_posts');

This code will check if the page is a single post, and if so, it will retrieve the author’s information.

Then, it will display a heading that says ‘Similar posts by (author name)’ and up to 5 similar posts (excluding the current post) by the same author below the post content. The function also tells WordPress to execute the code on single post templates.

After that, scroll down to the ‘Insertion’ section.

If it isn’t already selected, then choose ‘Auto Insert.’ Then, open the dropdown menu and choose ‘Run Everywhere’ so the related posts appear across your WordPress website.

Adding related posts across your WordPress website

After that, you are ready to scroll to the top of the screen and click on the ‘Inactive’ toggle so that it changes to ‘Active’.

Finally, click on ‘Save Snippet’ to make the PHP snippet live.

Clicking Save Snippet in WPCode

Now, if you visit any post on your WordPress blog, you will see a new related posts section.

We hope this article helped you learn how to easily display related posts by the same author in WordPress. You may also want to see our guide on how to display popular posts by views in WordPress or our expert picks for the best related posts plugins for WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

15 CommentsLeave a Reply

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. L Waterfield

    Apologies for opening this up again after all these years, but could you tell me how to place this related posts content somewhere other than “after entry content”? E.g. If I wanted it to appear after the author info or after the comments section? Thank you!

    • WPBeginner Support

      If you wanted to customize the specific location it appears then you would need to change ‘the_content’ to where you would like to add the content

      Admin

  3. azad

    How can Display Related Product by the Same Author in Wp sidebar

    • WPBeginner Support

      You would want to reach out to the support for the ecommerce plugin you are using for how to set that up.

      Admin

  4. Alex

    Great, Thank you for your article!
    is it possible to get same data from CPT?

    • WPBeginner Support

      To do that you would want to add to the array of arguments to include the post type. For line 8 you would want it to be:

      $authors_posts = get_posts( array( ‘post_type’ => ‘book’, ‘author’ => $authordata->ID, ‘post__not_in’ => array( $post->ID ), ‘posts_per_page’ => 5 ) );

      Replace book with your custom post type

      Admin

      • Alex

        Great! thank you!

        • WPBeginner Support

          You’re welcome :)

  5. Ryan Caswell

    Hi there, the code works great but is there any way to include the post featured image thumb too? This would be so amazing!

      • Ryan Caswell

        Great thanks! Sorry I am not much of PHP developer. Where would it go into the code to have it display? Thanks so much!

  6. Trishah Woolley

    Yes that works. Thanks!

    And I found and fixed another issue… If the author only has one post the Related Posts area shows but there is no information in it. To solve this, I did the following. And I also added a div around the content in order to style the area.

    // Related Author Posts
    
    function wpb_related_author_posts($content) {
    
        global $authordata, $post;
    
        $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
    
    if ( is_single() && (count($authors_posts) > 1 ) ) {
    
        $content .= '<div class="similar_posts"><h3>Similar Posts by The Author:</h3> ';
    
        $content .= '<ul>';
        foreach ( $authors_posts as $authors_post ) {
            $content .= '<li><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></li>';
        }
        $content .= '</ul></div>';
    
        return $content;
        }
        else {
        return $content;
        }
    }
    
    add_filter('the_content','wpb_related_author_posts');
    
  7. Trishah Woolley

    I’m testing the above functions.php code on a development site. The related posts are showing up on the bottom of pages also, like the contact us page. As you are using is_single this shouldn’t be happening. Do you have any insight on why this is happening?

    • WPBeginner Support

      Hi Trishah,

      Thanks for reporting this. There was a tiny error in the code that caused this. We have fixed the error, you can now try the new code snippet.

      Admin

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.