How we can get the user id by its display_name

You can use the following function:

function get_user_id_by_display_name( $display_name ) {
    global $wpdb;

    if ( ! $user = $wpdb->get_row( $wpdb->prepare(
        "SELECT `ID` FROM $wpdb->users WHERE `display_name` = %s", $display_name
    ) ) )
        return false;

    return $user->ID;
}

This is the same code get_user_by() uses, but since that function only allows ID, slug, email or login we have to create a new function.

Leave a Comment