How to show related post by same author in wordpress step by step

Shortlink:

Hi, today i will teach you, How to show related post by same author in WordPress, We will show you how to display related posts by the same author in WordPress without a plugin.

 

Step #01: Open your current active theme,

Step #02: Find functions.php file

Step #03: find ?> sign in last below,

Step #04: Copy below codes and past in your functions.php page

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

Note: Must be past above ?> sign

Then you need to open your single.php file (for twenty ten theme, loop-single.php), and paste the following code inside the loop where you like:

Now You can input the code where are you want to show posts

<?php echo wp_related_author_posts(); ?>

Function Reference

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!




%d bloggers like this: