How To Display Related Posts by the Same Author In WordPress

 

With a blog that has multiple authors, you may want to display posts that are related to the current post but written by the same author. In this article, we will show you how to display related posts by the same author in WordPress.

 

While WordPress supports various options for displaying related posts on your website, posts will be selected from all authors contributing to your content. If you wish to filter the selection to only include posts by the same author, you can do so using the Similar Posts plugin.

The plugin is one of many “related posts” plugins available for WordPress, however, it includes a wide assortment of options for controlling the display, layout, and selection of posts.

To get started, log into your WordPress administration dashboard, then head for Plugins > Add New. Search for “Similar Posts”, then install and activate the plugin.

 

 

Once activated, navigate to Settings > Similar Posts to configure the plugin’s settings.

 

Tabs across the top of the Settings page allow you to customize the selection, formatting, and display of related posts. At the bottom of the General tab, click the dropdown menu next to Match the current author’s posts and select Yes.

 

Next, you need to switch to the ‘Placement’ tab and activate the ‘Output after post’ option. You can also edit the output template by editing the text in the ‘Parameters’ box.

 

Don’t forget to click on the ‘Save Settings’ button to store your changes.

You can now visit any single post on your website, and you’ll see related posts by the same author after the post content.

This method requires you to add code to your WordPress theme files. This code snippet will allow you to display related posts by the same author. To do this we need to add some code into both the functions.php page and the single.php page.

Functions.php

First, add the following to your functions.php page.

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’ => 10 ) );

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

}

This will get posts by the current author where the post ID is not the current post and gets a maximum of 10 results.

Single.php

Now we have the function in the functions.php file we can use this inside the single.php file. Place a call to this function where you want this list appears.

      <?php echo get_related_athor_posts(); ?>

I hope this article helped you learn how to easily display related posts by the same author in WordPress. If so, I would love to hear about it in the comments below!

K2 Plugins has developed K2 blocks which is a WordPress plugin You can contact us for custom plugin development at our Official site