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();

Related posts

Leave a Reply

1 comment

  1. 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