WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 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

Your Answer


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.