Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm making some changes in my theme. I want that when they visit a Post the header should contain the post author and his URL. right now I'm using this:

echo '<a href="'.get_author_posts_url().'">'.get_userdata($posts[0]->post_author)->data->display_name.'</a>;

the auhtor's display name is working correctly, but the link is going like

www.mysite.com/?auhtor=0

instead of this (for example)

www.mysite.com/?auhtor=36

so this is the code in the header

<a href="http://www.mysite.com/?author=0">Display name</a>

instead of this:

<a href="http://www.mysite.com/?author=36">Display name</a>

by the way: I'm doing this outside a loop.

share|improve this question

2 Answers 2

You are probably calling it too early and the context for the current post is not filled yet. get_author_posts_url() accepts author's ID as first argument, You probably need to retrieve and pass that to it, similar to how you retrieve the info for following call.

share|improve this answer
    
thanks, that was the problem. –  Aly Saleem Dec 20 '13 at 17:46
up vote 0 down vote accepted

for anyone who's having this problem,this is the code I used:

 echo '<a href="'.get_author_posts_url(get_userdata($posts[0]->post_author)->data->ID).'">'.get_userdata($posts[0]->post_author)->data->display_name.'</a>';
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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