Support » Plugins » Hacks » get_var email address query error

  • I feel like I’m going crazy, but it’s definitely a WordPress issue. I am trying to get the ID of the user from the database (the user is not logged in yet). If given the following query:

    $print_user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$user_login_email'");
    echo $print_user_id;

    Where $user_login_email = something like “”. When I run this, it spits out nothing. If the user_login is not an email address, it works fine, but if it is, no dice. I’ve created another PHP file and run it manually outside of the WordPress environment and it works fine. I played around with different quotes, etc, to no avail. Am I missing something? Thank you for your help in advance.

    [No bumping – especially after only 1 hour. If it’s that urgent, consider hiring someone.]

Viewing 4 replies - 1 through 4 (of 4 total)
  • You can get a custom user object without having to query the DB by yourself like this:
    $User = get_user_by( 'email', $user_login_email );
    $User->ID would then give you the ID, for example.

    Good idea, however, I still have a problem. I create a file with the following code only:

    $User = get_user_by( ’email’, ‘’ );
    echo $User->ID;

    When I put this in the root of my WordPress site, it works. When it’s in the plugins directory it doesn’t. Same file (except I point to the wp-blog-header.php file differently). What’s going on? Any ideas?

    Moderator bcworkz


    Do you have any rewrites or permissions set that may affect access? Your page (with an email valid for my site) works fine in either location on my installation.

    Just recognized: Have you tried WHERE user_email instead of WHERE user_login in your SQL query?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘get_var email address query error’ is closed to new replies.