logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
Add Co-authors

Hello

I'm working on a site, and need to add co-author support to my custom posts, which are then displayed under each user that owns this post. There can be several.

Right now this function only supports 1 author, but I need this changed to multiple authors. Is this possible? I'm using the co-authors plus plugin.


function list_all_authors() {
if ( is_page( 33 /* Rejseledere */ ) ) :

global $wpdb;
$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users ORDER BY display_name");
?>
<div id="rejseledere" class="clearfix">
<?php foreach ( $authors as $author ) : ?>
<?php $aid = $author->ID; if ( $aid == 1 || $aid == 8 || $aid == 12 ) continue; ?>
<div class="author_info author-<?php the_author_meta( 'user_nicename', $aid ); ?>">
<span class="author_photo"><?php echo get_avatar( $aid, 96 ); ?></span>
<p><h2 style="color: #757a34;"><?php the_author_meta( 'display_name', $aid ); ?></h2></p>
<p><?php the_author_meta('description',$aid); ?></p>
<h4 style="padding-top: 10px;">Rejser med <?php the_author_meta( 'display_name', $aid ); ?></h4><?php /* </a> */ ?>
<ul class="postcatlist">
<?php
$result = '';
$authposts = get_posts('author=' . $aid . '&numberposts40' . $aid . '&post_type=destination');
foreach ( $authposts as $single ) :
$result .= '<li><a href="' . get_permalink( $single->ID ) . '">' . $single->post_title . '</a></li>';
endforeach;
echo $result;
?>
</ul>
</div>
<?php endforeach; ?>
</div>
<?php
endif;

This question has been answered.

René Sejling | 01/17/12 at 1:19pm Edit


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    01/17/12
    1:26pm
    Francisco Javier Carazo Gil says:

    Hi René,

    I don't know this plugin but I have been reading and it's not possible having more than one author in one post.

    I recommend you to use meta fields and save user_id inside it.

    • 01/17/12 1:28pm

      René Sejling says:

      Why is it not possible when there is a plugin that does it?
      Check this out, might help.. http://wordpress.org/extend/plugins/co-authors-plus/other_notes/

    • 01/17/12 1:33pm

      Francisco Javier Carazo Gil says:

      Hi René,

      Sorry. I have downloaded the plugin and I have seen the code.

      You can use this function:

      function get_coauthors( $post_id = 0, $args = array() )

    • 01/17/12 1:36pm

      Francisco Javier Carazo Gil says:

      In this file: template-tags.php you have useful functions.

    • 01/17/12 1:37pm

      René Sejling says:

      Cool

      How would I add it in the code above?
      I'm not the greatest programmor :)

      Thanks

    • 01/17/12 1:43pm

      Francisco Javier Carazo Gil says:

      get_coauthors returns an array with objects containing authors data. Each object you can get the data:


      <?php
      get_coauthors();

      foreach($authors as $user_info)
      {
      echo 'Username: ' . $user_info->user_login . "\n";
      echo 'User level: ' . $user_info->user_level . "\n";
      echo 'User ID: ' . $user_info->ID . "\n";
      }
      ?>

    • 01/17/12 2:04pm

      René Sejling says:

      Can't get it working.
      This part is the tricky one, I need this to list each post that each author is added to:


      <?php
      $result = '';
      $authposts = get_posts('author=' . $aid . '&numberposts40' . $aid . '&post_type=destination');
      foreach ( $authposts as $single ) :
      $result .= '<li><a href="' . get_permalink( $single->ID ) . '">' . $single->post_title . '</a></li>';
      endforeach;
      echo $result;
      ?>


      But no idea how to add the coauthors info in here. Hope you can help.

    • 01/18/12 2:36am

      Francisco Javier Carazo Gil says:

      René,

      Send me FTP credentials via PM and I will do it.

  • avatar
    Last edited:
    01/18/12
    1:39am
    Julio Potier says:

    Code not tested, i printed the coauthors after the permalink in your <li> because i don't know where you wanted to print it.

    <?php 			
    $result = '';
    $authposts = get_posts('author=' . $aid . '&numberposts=40' . $aid . '&post_type=destination');
    foreach ( $authposts as $single ) {
    $coauthors = get_coauthors( $single->ID );
    foreach ( $coauthors as $coauthor ) {
    $all_coauthors[] = $coauthor->user_nicename;
    }
    $result .= '<li><a href="' . get_permalink( $single->ID ) . '">' . $single->post_title . '</a> - Co-authors: ' . implode( ',', $all_coauthors ) . '</li>';
    }
    echo $result;
    ?>

    Previous versions of this answer: 01/18/12 at 1:39am

    • 01/18/12 1:40am

      Julio Potier says:

      ( take care you wrote "&numberposts40" instead of "&numberposts=40" )

This question has expired.



Gabriel Reguly, René Sejling, Julio Potier voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.