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 trying to get the author name using the "the_author_meta" function. After doing that I need to pass the value inside an array and return that with "json_encode".

Let me show:

$autor_id = $post->post_author;
$autor_name = the_author_meta('user_nicename', $autor_id);
echo $autor_name;

The $autor_name echo works fine but when i do the following code it returns null on my script:

...

$results['author'] = $autor_name;
$posts[] = $results;
}

return json_encode($posts);

it returns that: "author":null

How can i make it display the author name like: "author":admin?

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

The echoing is already done by the_author_meta().

echo $autor_name does nothing.

Correct would be to use get_the_author_meta().

share|improve this answer
    
Hi Scribu, first thanks for your fast reply. I feel really stupid hehe. Anyway I did the echo using the following code: $userid = $post->post_author; $userdata = get_userdata($userid); and then $userdata->user_nicename worked perfectly here too. But thanks a lot for the information –  Vitor Argos Apr 4 '11 at 2:54
    
You're welcome. –  scribu Apr 4 '11 at 3:21
add comment

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.