Aspire Built
Aspire Built

Reputation: 93

get user id from username - buddyPress

I need to get the id of the user by searching it on the input field. lets say i need an id of the user 'adre'(which is 33 actually). Any help would be appreciated.

// this way i can get username with user id.
$user_ID = 33;
$user = new BP_Core_User( $user_ID );
$user_array = $user->profile_data;
echo $user_nicename=$user_array['user_nicename']; // adre

// now i need to get user id by username.
//echo bp_displayed_user_id();

Upvotes: 1

Views: 2801

Answers (1)

jayant
jayant

Reputation: 116

Try this get_userdatabylogin

$user = get_userdatabylogin('admin');
var_dump($user);
echo $user->ID; // prints the id of the user

or this

 <?php $user = get_user_by( $field, $value ); ?> 

$field is for (string) (required) 'id', 'slug', 'email', or 'login'

$value is for (string|integer) (required) Search for this field value

    Default: None 

Upvotes: 1

Related Questions