如何通过元值获取wordpress用户ID?

时间:2013-09-20 14:51:16

标签: wordpress

有一个:

<?php //...................

$user = get_user_by( 'email', 'user@example.com' );
echo $user->ID; /* User id */

?>

但是,在wp_users表上工作。

  

user_login,user_email,user_nicename

我需要工作特殊的元键和值。

  

USER_PHONE

截图:

enter image description here

谢谢大家。

1 个答案:

答案 0 :(得分:2)

/* delete login on user_login 
    if ( ! empty( $username ) )
        $user = get_user_by( 'login', $username );

    if ( isset( $user->user_login, $user ) )
        $username = $user->user_email;
*/
/* add login with user_phone  (in wp_user_meta) */
    if ( ! empty( $username ) )
        $user = reset( get_users(
                              array(
                               'meta_key' => 'user_phone',
                               'meta_value' => $username,
                               'number' => 1,
                               'count_total' => false
                          ) ) );

    if ( isset( $user->user_login, $user ) )
        $username = $user->user_email;
/* /end/ add PHONE */

/* Add user login with user_email (in wp_users) */

    $user = get_user_by('email', $username);

干得好:):