• Hello, we have some weird use cases on a website, and we have a function that checks the author of the current post and returns a list of posts by the same author. It works fine by itself. We were hoping it would continue to work correctly after adding the Co-Authors-Plus plugin. However it seems to only associate the posts with the first author added.

    This function uses global authordata, does this plugin extend that or have its own global I can glob onto?

    function xxx_get_related_author_posts() {
    	global $authordata, $post;
    	$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) );
    	if ( ! empty( $authors_posts ) ) {
    		$output = '';
    	}
    	foreach ( $authors_posts as $authors_post ) {
    		$output .= '<div><a href="' . get_permalink( $authors_post->ID ) . '" class="d-flex"><i class="far fa-newspaper"></i> ' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a></div>';
    	}
    	return $output;
    	wp_reset_postdata();
    }

    Thanks

  • The topic ‘Getting Posts by coauthors’ is closed to new replies.