get_user_by(“email… not working

Here I attempt to get a user by email, passing it an email stored in the student variable.

$user = get_user_by("email", $student);

Student variable

Read More
echo $student;
>>> xxxx.xxxxx@xxxxxx.co.uk

I can confirm this email is correct and exists as a users email.

var_dump($user);
>>> (false)

I’m currently editing within a pdf_certificates generator plugin.

Is there any reason I shouldn’t be able to access this user? Cheers guys.

Related posts

2 comments

  1. Try this

        $email = "xxx@xxx.com";
        if ( email_exists( $email ) ){  
            $user = get_user_by("email", $email);
            print_r($user);
            echo $username = $user->user_login;
        }else{
           echo "Email id does not exist.";
        }
    

Comments are closed.