0%

Wordpress 跟据用户邮箱获得用户ID

1
2
3
4
5
6
7
8
function get_user_id($mail){  
$user="'".$mail."'";
global $wpdb;
$user_ids = $wpdb->get_col("SELECT ID FROM $wpdb->users WHERE user_email = $user ORDER BY ID");
foreach($user_ids as $user_id){
return $user_id;
}
}

调用的时候在页面中直接添加

1
2
3
<?php
echo get_user_id(邮箱); //显示用户ID
?>