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
?
The echoing is already done by the_author_meta().
echo $autor_name
does nothing.Correct would be to use get_the_author_meta().