drap5081683 2017-10-16 16:25
浏览 116
已采纳

Wordpress - get_user_by()返回false

I must be doing something wrong, but the following commented code returns false. Note that WP is returning 'admin' as the 'user_login', but when that user_login is used for the get_user_by() function it simply returns false. Am I missing something?

$user = get_userdata(1); // (admin ID is 1)

var_dump($user->user_login); // string(5) 'admin'
var_dump(get_user_by('user_login', $user->user_login)); // bool(false)

I am running WordPress 4.8.2

  • 写回答

2条回答 默认 最新

  • dongma7725 2017-10-16 16:27
    关注

    I believe you'll need to use "login" rather by "user_login" in the get_user_by call.

    See the posssible accepted values of the function here: https://developer.wordpress.org/reference/functions/get_user_by/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?