【发布时间】:2017-06-05 18:26:46
【问题描述】:
我对标准 wp 函数 get_the_author_meta() 有一些问题。我在我的项目中使用它来显示作者的社交链接,但我总是得到一个空变量。
这是我在文章页面中的代码:
$author_name = get_the_author();//not empty
$author_info = get_the_author_meta('description');//not empty
$author_website = get_the_author_meta('url');//empty
$author_facebook = get_the_author_meta('facebook');//empty
$author_twitter = get_the_author_meta('twitter');//empty
$author_google = get_the_author_meta('google');//empty
$author_linkedin = get_the_author_meta('linkedin','7');//also empty whit this desperate attempt
$author_instagram = get_the_author_meta('instagram',7);//also empty whit this desperate attempt
我测试了具有所有社交链接的作者的文章。 我没有 php 没有 js 错误。 我安装了 cimy 用户额外字段。
【问题讨论】:
-
为什么不先转储作者数据,看看这些字段是否存在。
-
var_dump(get_the_author_meta());//string(0) "" var_dump(get_the_author_meta(7));//string(0) "" var_dump(get_the_author_meta('7'));/ /string(0) "" 最奇怪的是所有这些字段都存在并且在数据库中不为空。
-
某事告诉我您正在使用插件将这些社交链接添加给作者。根据 Codex,返回空字符串的字段不是有效字段。 codex.wordpress.org/Function_Reference/the_author_meta
-
是的,我加了。您可以在 DB 上找到确切的元数据(facebook、Twitter excetera)。