Skip to content

Commit

Permalink
Try to get author first by author_id then if not set default to findi…
Browse files Browse the repository at this point in the history
…ng author by user_nicename. This fixes issue with all posts on author archive page being the same author even if there is other post loops on page that do not belong to author.
  • Loading branch information
mattpramschufer authored and GaryJones committed Jul 24, 2023
1 parent 3c66e21 commit 79339c4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions co-authors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ function current_user_can_set_authors() {
*/
public function fix_author_page( $selection ) {

global $wp_query, $authordata;
global $wp_query, $authordata, $post;

if ( ! isset( $wp_query ) ) {
return;
Expand All @@ -1194,7 +1194,12 @@ public function fix_author_page( $selection ) {
return;
}

$author = $this->get_coauthor_by( 'user_nicename', $author_name );
if ( ! isset( $post->post_author ) ) {
$author = $this->get_coauthor_by( 'user_nicename', $author_name );
} else {
$author = $this->get_coauthor_by( 'id', $post->post_author );
}

if ( is_object( $author ) ) {
$authordata = $author; //phpcs:ignore
$term = $this->get_author_term( $authordata );
Expand Down

0 comments on commit 79339c4

Please sign in to comment.