Co-Authors-Plus icon indicating copy to clipboard operation
Co-Authors-Plus copied to clipboard

Missing Archive Title, Description for Guest Authors on author archive pages

Open laurelfulford opened this issue 3 years ago • 1 comments

I ran into an issue with the Newspack theme where the_archive_title() and get_the_archive_description() were returning blank for Guest Authors sometimes.

For me, this was only happening when I had no menus assigned to the site.

@leogermani did some investigating and tracked down a cause -- I've paraphrased his findings below:

CoAuthors Plus relies on the posts_selection hook to fix the author data in the global $wp_query object, and this hook runs whenever a query is made.

When there is no query made before the author name is displayed (like if the site doesn't have a menu, or anything that queries posts before the content), the hook doesn't fire and the $wp_query is still wrong.

If there is a query, things get fixed; that query could be anything, not just a menu [another example that fixed it for me was turning on Yoast's breadcrumbs].

When that happens, the first global query happens before $GLOBALS['authordata'] = get_userdata( get_queried_object_id() );, so the global $authordata CoAuthors Plus creates gets overwritten.

For most Guest Authors it gets overwritten with nothing (resulting in the empty title and description on the Author Archives page). However, if a Guest Author happens to share an ID with a regular WP User, the title and description will get overwritten by that user's information instead.

Is it possible to have the plugin override the global $authordata even in cases like this?

laurelfulford avatar Dec 23 '22 00:12 laurelfulford

Bump - this also applies to gutenberg themes. Archive Title block gets the author name, but there's no block for getting the archive author description

albanyacademy avatar Aug 01 '24 19:08 albanyacademy