Adding Author Box Meta Links with Co-Authors

I have a site that has multiple authors for a single post, requiring multiple author box bios after the article.

I previously used get_the_author_meta() to pull the user's social media hyperlinks as clickable icons beneath the author description, but when using a foreach loop with co-authors only the first author's social media links are used.

I've tried changing the arguments $author_id to $coauthor_id, but this does not seem to work. Using get_the_co_author just pulls all the css sprite icons without the hyperlinks.

I know the original get_the_author_meta() code works because it still functions on single author posts, I just can't seem to convert it to be compatible with co-authors.

?php

$twitter  = get_the_author_meta('twitter', $author_id);
$facebook = get_the_author_meta('facebook', $author_id);
$googleplus = get_the_author_meta('googleplus', $author_id);
$linkedin = get_the_author_meta('linkedin', $author_id);
$instagram = get_the_author_meta('instagram', $author_id);
$youtube = get_the_author_meta('youtube', $author_id);
$email = get_the_author_meta('email', $author_id);

global $post;
$author_id=$post-post_author;
foreach( get_coauthors() as $coauthor ): ?

div class="author-box"
div class="author-avatar"
?php echo get_avatar( $coauthor-user_email, '96' ); ?
/div

div class="author-description"
h5 class="author vcard"span class="fn"a href="?php echo get_author_posts_url( $coauthor-ID, $coauthor-user_nicename ); ?"?php echo $coauthor-display_name; ?/a/span/h5
p class="author-bio"?php echo $coauthor-description; ?/p
/div

div class="author-box-social-icons"
?php   
        if(!empty($email)) {
echo 'a title="Email" href="mailto:'.$email.'" id="author-social-email"/a';
}       
        if(!empty($instagram)) {
echo 'a title="Instagram" href="'.$instagram.'" id="author-social-instagram"/a';
}       
        if(!empty($youtube)) {
echo 'a title="YouTube" href="'.$youtube.'" id="author-social-youtube"/a';
}       
        if(!empty($linkedin)) {
echo 'a title="Follow me on LinkedIn" href="'.$linkedin.'" id="author-social-linkedin"/a';
}               
        if(!empty($googleplus)) {
echo 'a title="Follow me on Google Plus" href="'.$googleplus.'" id="author-social-googleplus"/a';
}                   
        if(!empty($twitter)) {
echo 'a title="Follow me on Twitter" href="https://twitter.com/'.$twitter.'" id="author-social-twitter"/a';
}
        if(!empty($facebook)) {
echo 'a title="Follow me on Facebook" href="'.$facebook.'" id="author-social-facebook"/a';
}       

?
/div  

div class="clear"/div
/div!-- .entry-author co-author --

?php endforeach;?

Topic multi-author user-meta php author-template Wordpress

Category Web


These are outside of the foreach loop:

$twitter  = get_the_author_meta('twitter', $author_id);
$facebook = get_the_author_meta('facebook', $author_id);
$googleplus = get_the_author_meta('googleplus', $author_id);
$linkedin = get_the_author_meta('linkedin', $author_id);
$instagram = get_the_author_meta('instagram', $author_id);
$youtube = get_the_author_meta('youtube', $author_id);
$email = get_the_author_meta('email', $author_id);

So (remove that, and) try using $coauthor->ID with get_the_author_meta() like this:

<div class="author-box-social-icons">
<?php   
        if( $email = get_the_author_meta( 'email', $coauthor->ID ) ) {
echo '<a title="Email" href="mailto:'.$email.'" id="author-social-email"></a>';
}       
        if( $instagram = get_the_author_meta( 'instagram', $coauthor->ID ) ) {
echo '<a title="Instagram" href="'.$instagram.'" id="author-social-instagram"></a>';
}       
        if( $youtube = get_the_author_meta( 'youtube', $coauthor->ID ) ) {
echo '<a title="YouTube" href="'.$youtube.'" id="author-social-youtube"></a>';
}       
        if( $linkedin = get_the_author_meta( 'linkedin', $coauthor->ID ) ) {
echo '<a title="Follow me on LinkedIn" href="'.$linkedin.'" id="author-social-linkedin"></a>';
}               
        if( $googleplus = get_the_author_meta( 'googleplus', $coauthor->ID ) ) {
echo '<a title="Follow me on Google Plus" href="'.$googleplus.'" id="author-social-googleplus"></a>';
}                   
        if( $twitter = get_the_author_meta( 'twitter', $coauthor->ID ) ) {
echo '<a title="Follow me on Twitter" href="https://twitter.com/'.$twitter.'" id="author-social-twitter"></a>';
}
        if( $facebook = get_the_author_meta( 'facebook', $coauthor->ID ) ) {
echo '<a title="Follow me on Facebook" href="'.$facebook.'" id="author-social-facebook"></a>';
}       

?>
</div>

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.