Display Related Posts by “Category” “by Author”

Question

How can I display related post “by category” “by author”? I use this code but it just displays related posts by newest posts of author, not related posts by category of author. I’ve done some research on the internet but cannot find an answer.

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' => 3 ) );
$output = '<div class="rp-users">';
foreach ( $authors_posts as $authors_post ) {
    $output .= '<div class="rp-user-entry">';
    $output .= get_the_post_thumbnail($authors_post->ID, 'related-post-size');
    $output .= '<a href="' . get_permalink( $authors_post->ID ) . '"class="rp-title">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
    $output .= '</div>';
}
$output .= '</div>';
return $output;

--------------------------------------------------

>>> Share a link to this question, just copy and paste the code bellow on your web page <<<

<a href="https://www.wptricks.com/question/display-related-posts-by-category-by-author/">

Display Related Posts by "Category" "by Author"</a>
0
, user125393 3 years 0 Answers 39 views 0

Leave an answer