get id from username wp getuserby
To get the user ID from a username in WordPress, you can use the get_user_by() function. Here's an example:
$username = 'john.doe';
$user = get_user_by( 'login', $username );
if ( $user ) {
$user_id = $user->ID;
echo "The user ID for $username is $user_id.";
} else {
echo "User $username not found.";
}
In this example, we're looking up the user with the username 'john.doe' using the 'login' parameter of get_user_by(). If the user is found, we retrieve their ID from the $user object and print it out. If the user is not found, we print a message saying so
原文地址: http://www.cveoy.top/t/topic/dW26 著作权归作者所有。请勿转载和采集!