I need help. I need to get a user ID or email (email is can do but ID is better) based on their phone number, outside of WordPress. I already have their phone number in a variable and billing_phone is custom metadata in the wp_users table. This is what I am using to load wp
`$parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] ); require_once( $parse_uri[0] . 'wp-load.php' );`
and how I am fetching the email.
`$email = $wpdb->get_var("SELECT user_email FROM wp_users WHERE billing_phone = $phone_number ");`
Thank you all in advance. Any help is appreciated.
wp-load.php
that way looks like you are loading it from within a plugin. This is generally not a good idea. What are you trying to do?wp_users
table. And you don't needwp-load.php
to query the database. Use plain mySQL query from your external script.