Sometimes when we are working on a section where we need user details like user email. In a case where we only have the display name of a user and we want to fetch email id of that user use below mentioned code :


<?php  
    global $wpdb;
    $required_users = $wpdb->get_results("SELECT user_email FROM $wpdb->users WHERE display_name = 'display_name'");
    $user_email = $required_users[0]->user_email;
    echo $user_email;
?>

 

In the above query just pass the “display_name” of a user for which you want to fetch the email id. The required result be in $user_email variable.