Caveat- I'm not a programmer, I'm a designer that has taught myself basic php/wordpress theming.

This is a very specific question, I realize, but I'm hoping the experts can help me find some universal principle I've overlooked.

I am using the plugin posts 2 posts to generate a relationship between the CPT "speakers" to wordpress users (Relevant plugin documentation)

I then want to show, on the single page for speakers, a link to all the blog posts by the related users. My problem is that get_author_posts_url returns a link to the correct related user, while get_the author gets some other, seemingly random user. All this within the same query!

This is my code:

$users = get_users( array(
    'connected_type' => 'authors_to_speakers',
    'connected_items' => $post,
) );
foreach ( $users as $spost ){
    echo '<div class="related-tour-item"><a href="';
    echo get_author_posts_url($spost->ID);
    echo '">All posts by';
    echo get_the_author($spost->ID);
    echo '</a></div>';


The output is a correct link to the right author archive page and then another (different) user's name

Any clues?


Sebastien's answer got me on the right track. I should not be using the_author, because I am not looking for the author of a post (My query is not returning a post, but a user), rather the name of the user.

I changed:

echo get_the_author($spost->ID);


 echo $spost->display_name;
| improve this answer | |
  • I was about to tell you haha... Nice job – Sebastien Apr 16 '15 at 8:32

get_the_author() takes no arguments and must be used within the Loop (I guess it's the case).

/* get_the_author($spost->ID); Replace this. */
get_the_author(); // By this.
| improve this answer | |
  • but $users is already returning users and not posts since I'm using get_users and not get_posts, right? so $spost should also be a user – spiral Apr 16 '15 at 8:22
  • 1
    You're right indeed. It's a bit confusing you called it $spost. Well, that means you're not running trough a custom Loop, the get_the_author() will return the author of the current page or something like that. – Sebastien Apr 16 '15 at 8:33

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.