我正在尝试使用“作者名称”the_author_meta“函数。这样做之后,我需要传递数组中的值,然后用“ json_encode”返回该值。

让我展示:

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

$autor_name echo 正常工作,但是当我执行以下代码时,它会在我的脚本上返回null:

...

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

return json_encode($posts);

它返回: "author":null

我如何使其显示作者名称,例如: "author":admin?

有帮助吗?

解决方案

回声已经由the_author_meta()完成。

echo $autor_name 什么也没做。

正确的是使用get_the_author_meta()。

许可以下: CC-BY-SA归因
scroll top