Thread Starter
Eric
(@eklemen2)
P.S. What I’m trying to do is create a custom author.php page that displays the same info for post authors (account holders) as co-authors (non-account holders).
Thanks again!
Thread Starter
Eric
(@eklemen2)
P.S. This is what I ended up doing to the time being. It feels dirty. Is there a better way?
// If there's a cleaner way to do this, I haven't found out how. The author data seems to be accessed differently for account-holding authors and non-account co-authors (created by co-authors plus plugin) when using custom fields (created by Advanced Custom Fields).
// Default all author values to null
$this_author_display_name = $this_author_title = $this_author_email = $this_author_phone_number = $this_author_linkedin = $this_author_twitter = $this_author_biography = null;
// Co-Authors (non custom fields also return for account-holding authors)
$coauthors = get_coauthors();
foreach( $coauthors as $coauthor ){
$this_author_display_name = get_the_author();
if( get_post_meta( $coauthor->ID, 'guest_author_title', true ) ){
$this_author_title = get_post_meta( $coauthor->ID, 'guest_author_title', true );
}
if( $coauthor->user_email ){
$this_author_email = $coauthor->user_email;
}
if( get_post_meta( $coauthor->ID, 'guest_author_phone_number', true ) ){
$this_author_phone_number = get_post_meta( $coauthor->ID, 'guest_author_phone_number', true );
}
if( get_post_meta( $coauthor->ID, 'guest_author_linkedin', true ) ){
$this_author_linkedin = get_post_meta( $coauthor->ID, 'guest_author_linkedin', true );
}
if( get_post_meta( $coauthor->ID, 'guest_author_twitter', true ) ){
$this_author_twitter = get_post_meta( $coauthor->ID, 'guest_author_twitter', true );
}
if( $coauthor->description ){
$this_author_biography = $coauthor->description;
}
}
// Account Holding Authors (custom fields)
if( get_the_author_meta( 'guest_author_title' ) ){
$this_author_title = get_the_author_meta( 'guest_author_title' );
}
if( get_the_author_meta( 'guest_author_phone_number' ) ){
$this_author_phone_number = get_the_author_meta( 'guest_author_phone_number' );
}
if( get_the_author_meta( 'guest_author_linkedin' ) ){
$this_author_linkedin = get_the_author_meta( 'guest_author_linkedin' );
}
if( get_the_author_meta( 'guest_author_twitter' ) ){
$this_author_twitter = get_the_author_meta( 'guest_author_twitter' );
}
Thread Starter
Eric
(@eklemen2)
Through trial and error, I discovered the foreach loop was not needed on author.php archive page. A little more streamlined than my last comment.
$this_author_display_name = get_the_author();
if( get_the_author_meta( 'guest_author_title' ) ){
// account authors
$this_author_title = get_the_author_meta( 'guest_author_title' );
} elseif( get_post_meta( $authorID, 'guest_author_title', true ) ){
// CAP guest author
$this_author_title = get_post_meta( $authorID, 'guest_author_title', true );
}
if( get_the_author_meta( 'email' ) ){
$this_author_email = get_the_author_meta( 'email' );
}
if( get_the_author_meta( 'guest_author_phone_number' ) ){
// account authors
$this_author_phone_number = get_the_author_meta( 'guest_author_phone_number' );
} elseif( get_post_meta( $authorID, 'guest_author_phone_number', true ) ){
// CAP guest authors
$this_author_phone_number = get_post_meta( $authorID, 'guest_author_phone_number', true );
}
if( get_the_author_meta( 'guest_author_linkedin' ) ){
// account authors
$this_author_linkedin = get_the_author_meta( 'guest_author_linkedin' );
} elseif( get_post_meta( $authorID, 'guest_author_linkedin', true ) ){
// CAP guest authors
$this_author_linkedin = get_post_meta( $authorID, 'guest_author_linkedin', true );
}
if( get_the_author_meta( 'guest_author_twitter' ) ){
// account authors
$this_author_twitter = get_the_author_meta( 'guest_author_twitter' );
} elseif( get_post_meta( $authorID, 'guest_author_twitter', true ) ){
// CAP guest authors
$this_author_twitter = get_post_meta( $authorID, 'guest_author_twitter', true );
}
if( get_the_author_meta( 'description' ) ){
$this_author_description = get_the_author_meta( 'description' );
}