I've recently installed the Co-Authors Plus plugin and am trying to get all the authors from a post within a post loop. However for some reason when I use get_queried_object()
, there is only one author listed not multiple.
Is there a way to get all the authors from a post using WP_Query
or some other manner?
I've recently installed the Co-Authors Plus plugin and am trying to get all the authors from a post within a post loop. However for some reason when I use get_queried_object()
, there is only one author listed not multiple.
Is there a way to get all the authors from a post using WP_Query
or some other manner?
- Do you mean all authors? – Gufran Hasan Commented Nov 12, 2018 at 10:24
- No, I mean all the authors from that one post, so if I add 2 users to the post e.g. Admin and myself, I want to be able to get both admin and myself in another wordpress loop e.g. archive page with a WP_Query – ParadAUX Commented Nov 12, 2018 at 10:27
- 1 @GufranHasan Please stop misusing code markup. Thank you. – fuxia ♦ Commented Nov 12, 2018 at 15:35
- @fuxia, Okay thanks, I will take care it next time :) – Gufran Hasan Commented Nov 12, 2018 at 15:37
1 Answer
Reset to default 1If you are using Co-Authors Plus plugin. By default, it will show the original author of the post.
You’ll need to edit theme files with the code responsible for showing the author name for posts. This could be single.php, content.php,
or a template tag in your theme’s functions.php
file.
the_author_posts_link()
and you will need to replace it with the following code snippet.
if ( function_exists( 'coauthors_posts_links' ) ) {
coauthors_posts_links();
} else {
the_author_posts_link();
}
Reference
You can use the following code to get co-authors.
<?php $coauthors = get_coauthors(); ?>
<?php foreach( $coauthors as $coauthor ): ?>
<center><div class="authbio">
<img src="<?php bloginfo('template_url'); ?>/images/<?php echo $coauthor->user_firstname; ?>.jpg" alt="" class="alignleft"/>
<?php $userdata = get_userdata( $coauthor->ID ); ?>
<?php if ( $userdata->user_description ) echo $userdata->user_description; ?>
</div></center>
<?php endforeach; ?>