Support » Plugin: Co-Authors Plus » Post not showing up under the all of the coauthor's posts.

  • Resolved HeroicSlinky

    (@heroicslinky)


    Hello I was wondering if anybody could help me out. My main problem is that posts that have two authors are only showing up under one author currently. For my main problem I have placed the code in a pastebin. Thanks ahead for helping me out.

    http://pastebin.com/JTfxz2Yp

    A secondary issue is that the coauthors names are being duplicated like the two examples below. I am using the coauthors() function Examples of the code I am using to get these are.

    Example One:

    LindsayThis entry was contributed by Lindsay, October 26th, 2015 at 1:04 pm and is filed under Capacity Building, Community Partnerships, Diversity.

    Example Two:

    This entry was contributed by Lindsay and LindsayLindsay and Lindsay, October 26th, 2015 at 1:04 pm and is filed under Capacity Building, Community Partnerships, Diversity.

    Code Example:

    <?php if( function_exists( 'coauthors' ) ) :
    	echo '<span class="post-author-meta">This entry was ' . __( 'contributed by', 'reverie' )  coauthors() . ', ' . get_the_time( 'F jS, Y \a\\t g:i a' );
    else :
    	echo '<span class="post-author-meta">This entry was ' . __( 'contributed by', 'reverie' ) get_the_author_meta( 'display_name' ) . ', ' . get_the_time( 'F jS, Y \a\\t g:i a' );
    endif; 
    
    $coauthors = get_coauthors();
    
    foreach( $coauthors as $coauthor ):
    $userdata = get_userdata( $coauthor->ID ); ?>
    
    <div class="entry-author panel contributor-title">
    	<div class="row">
    		<div class="large-3 columns">
    			<div class="img"><?php echo get_avatar( $userdata->user_email, 95 ); ?></div>
    
    			<div class="name"><a href="/contributors"><?php echo $userdata->display_name; ?></a></div>
    		</div>
    
    		<div class="large-9 columns">
    			<p class="cover-description"><?php echo $userdata->user_description; ?></p>
    		</div>
    	</div>
    </div>
    <?php endforeach;?>

    https://wordpress.org/plugins/co-authors-plus/

Viewing 1 replies (of 1 total)
  • Thread Starter HeroicSlinky

    (@heroicslinky)

    Was able to figure out both problems. For my main problem where the posts that were not showing up under both of the authors. By including the get_post_taxonomies function in the posts arguments array this seems to have fixed that main problem problem.:

    <?php $author_args = array(
    	'offset'                    =>  0,
    	'orderby'                 =>  'post_date',
    	'order'                     =>  'DESC',
    	<strong>'include'                  =>  get_post_taxonomies( 'author' ),</strong>
    	'author'                   =>  $contributor_id,
    	'post_type'              =>  'post',
    	'post_status'           =>  'publish',
    	'posts_per_page'    =>  -1,
    	'suppress_filters'     =>  true,
    );
    
    // Gets the posts for each contributor.
    $posts = get_posts( $author_args );
    
    if ( $posts ):
    	foreach ( $posts as $post ) : setup_postdata( $post );
    
    		// post information here
    
    	endforeach;
    endif; ?>

    For the second problem with the duplication of the co-authors was solved by doing this,
    although this could be improved upon:

    <?php if ( $posts ):
    	foreach ( $posts as $post ) : setup_postdata( $post );
    		// Setting up the coauthors variable
    		$coauthors = get_coauthors();
    
    		// Counter for the coauthors foreach loop below
    		$coauth = 0;
    
    		// Counting the number of objects in the array.
    		$len = count( $coauthors );
    
    		echo '<div class="post">';
    			// Meta data here...
    
    			foreach( $coauthors as $coauthor ):
    				// Updating the counter.
    				$coauth++;
    
    				// Getting the data for the current author
    				$userdata = get_userdata( $coauthor->ID );
    
    				// If one object in the array
    				if ( $coauth == 0 ):
    					// Just the authors name
    					echo $userdata->display_name;
    				// If more than one object in the array
    				elseif ( $coauth >= 1 ):
    					// Adding a "comma" after the name
    					echo $userdata->display_name . ', ';
    				// If last object in the array
    				elseif ( $coauth == $len - 1 ):
    					// Adding an "and" before the last object
    					echo ' and ' . $userdata->display_name;
    				endif;
    			endforeach;
    
    			// More meta data here...
    		echo '</div>';
    	endforeach;
    endif; ?>

    Hope that this helps someone else out in the future if they have a similar problem!!

Viewing 1 replies (of 1 total)
  • The topic ‘Post not showing up under the all of the coauthor's posts.’ is closed to new replies.