Php 获取不在wp上工作的\u作者\u meta()

Php 获取不在wp上工作的\u作者\u meta(),php,wordpress,Php,Wordpress,我对标准wp函数有一些问题。我在我的项目中使用它来显示作者的社交链接,但我总是得到一个空变量 以下是我在文章页面中的代码: $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_

我对标准wp函数有一些问题。我在我的项目中使用它来显示作者的社交链接,但我总是得到一个空变量

以下是我在文章页面中的代码:

    $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用户额外字段。

首先,这里有一个额外的逗号$author\u facebook=get\u the\u author\u meta('facebook',)//空的

我猜这是复制粘贴中的一个错误,否则会出现一个非常具体的“意外标记”错误。除此之外,您的代码应该可以工作。出现此错误的原因可能有两个:

  • 用于添加用户元的插件无法正常工作
  • 页面/文章的实际作者没有正确设置元数据
  • 此代码对我有效,请尝试以下测试:

    $user_id = get_the_author_meta( 'ID' );
    add_user_meta( $user_id, 'facebook', 'https://facebook.com' );
    
    var_dump( $user_id );
    var_dump( get_the_author_meta( 'facebook' ) );
    
    // Output: string(20) "https://facebook.com"
    

    您之前提到,您可以在数据库的usermeta下看到社交媒体链接,因此我猜当前的文章/页面作者没有设置社交媒体链接。在代码的var_转储中,您将看到用户ID。在数据库中找到具有该用户ID的表usermeta的所有条目,您将注意到该特定用户没有自定义meta。

    为什么不先转储作者数据,看看这些字段是否在第一位。var_转储(get_the_author_meta())//字符串(0)“”变量转储(获取作者元数据(7))//字符串(0)“”变量转储(获取作者元('7')//字符串(0)”“最重要的是,所有这些字段在数据库中都存在,并且不是空的。有消息告诉我,您正在使用插件将这些社交链接添加到作者。根据法典,返回空字符串的字段无效。是的,我加上了。你可以在DB上找到确切的metas(facebook,Twitter excetera)。非常感谢你的解释。现在我终于得到了完整的过程。我还有一个额外的错误:-我将“google”替换为“googleplus”