0

I have a CPT that has multiple authors. I've added the multiple author functionality with the Co-Author plugin https://wordpress.org/plugins/co-authors-plus/

I also have an author page (author.php) that should list the CPT associated with the author. This is fine as long as the CPT has a single author. If the CPT has multiple author assigned it only recognizes the 'first' listed author and not the other authors.

To show the CPT(s) the author is assigned to I'm using the following code:

<?php
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif;
?>

<?php 
$loopTypes = new WP_Query( array( 'post_type' => 'opleidingen', 'author' =>    $curauth->ID ));?>

<ul>

<?php if ($loopTypes->have_posts()) : while ($loopTypes->have_posts()) : $loopTypes->the_post();  ?>

<li><a href="<?php the_permalink (); ?>"><?php the_title (); ?></a></li>    

<?php endwhile; ?>
</ul>
<?php else : ?>
<?php endif; ?>
<?php wp_reset_query();?>

Is there a way to alter/extend this code to display all assigned authors of the CPT and not only the first one?

Thanks.

2

The Co-Authors Plus plugin uses it's own template tags which replace the default WordPress tags, the_author() and the_author_posts_link().

  • coauthors() - Outputs the co-authors display names, without links to their posts.
  • coauthors_posts_links() - Outputs the co-authors display names, with links to their posts.
  • coauthors_links() - Outputs the co-authors display names, with links to their websites if they've provided them.

You'll need to add one of those functions to your code.

For specific examples, see the Co-Authors Plus Documentation.

  • @NielsPilon great. If it worked out for you, please accept my answer. :-) – cowgill Oct 7 '16 at 0:20
  • Well the documentation is very limited unfortunately. There's an example which should list all posts of a guest author however the output is wrong. Been searching for a while now but only find mostly frustrated answers about the poor documentation and not many usefull answers / code examples. – NielsPilon Oct 7 '16 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.