Display Related Posts by “Category” “by Author”

Sounds like you want to get the related posts from the same category as the current post that is written by the same author. In order to do this you will want to create a custom loop using the WP_Query Class which will look something like this:

$author_id = get_the_author();
$category_id = get_the_category();

$args = array(
    'author'         => $author_id,
    'category'       => $category_id[0],
    'posts_per_page' => 5,
);

$rel_posts = new WP_Query( $args );

if( $rel_posts->have_posts() ) { 
    echo '<div class="related-posts">' . PHP_EOL;
    echo '<ul>' . PHP_EOL;
    while ( $rel_posts->have-posts() ) {
        echo '<li class="related-post"><a href="' . esc_url( get_the_permalink() ) . '>' . esc_html( get_the_title() ) . '</a></li>' . PHP_EOL;
    }
    echo '</ul>';

    // Reset Post Data
    wp_reset_postdata();

    } else {
        // No Posts Found
    }
}

What this code does is it grabs the author ID from the current post as well as the array of categories the post has (Note: get_the_category() will always return an array even if only one is assigned. It will return the ID, Name, and Slug).

We then feed it into the $args array using $category_id[0] to grab the ID of the first category in the array. For demonstration purposes, I also tell the query to only grab 5 posts.

It will then open up an unordered list and loop through the posts WP_Query found and create a list item for each one containing a link. Once it’s done, we close the unordered list and reset the post data back to the original one.

Note: You can ommit the . PHP_EOL part of the echo statements. That just adds a line break at the end which I like to do for diagnostic purposes so the resulting HTML code is easier to read.