最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Co-Authors Plus: How do I get all authors with a query?

programmeradmin2浏览0评论

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?

Share Improve this question edited Nov 12, 2018 at 10:45 kero 6,3401 gold badge25 silver badges34 bronze badges asked Nov 12, 2018 at 10:11 ParadAUXParadAUX 11 silver badge1 bronze badge 4
  • 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
Add a comment  | 

1 Answer 1

Reset to default 1

If 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; ?>
发布评论

评论列表(0)

  1. 暂无评论