4

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?

1 Answer 1

8

The echoing is already done by the_author_meta().

echo $autor_name does nothing.

Correct would be to use get_the_author_meta().

1
  • 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 Commented Apr 4, 2011 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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