public
Last active

Fix for 2.1.1 with wrong author info being pulled on author pages

  • Download Gist
coauthors-plus-author-page-fix.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
/**
* Fix for author info not properly displaying on author pages
*
* On an author archive, if the first story has coauthors and
* the first author is NOT the same as the author for the archive,
* the query_var is changed.
*
*/
function coa_fix_author_page( &$post ) {
 
if( is_author() ) {
global $wp_query, $authordata;
 
// Get the id of the author whose page we're on
$author_id = $wp_query->get( 'author' );
 
// Check that the the author matches the first author of the first post
if( $author_id != $authordata->ID ) {
// The IDs don't match, so we need to force the $authordata to the one we want
$authordata = get_userdata( $author_id );
}
}
}
// Fix for author info not properly displaying on author pages
add_action( 'the_post', 'coa_fix_author_page' );

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.