douxin8610 2013-09-19 18:18
浏览 31
已采纳

WordPress:从每个用户记录中选择wp_users和wp_metadata中的所有关联元数据到一行

This is how I've been able to extract all of the relavant data into a single row for each user record:

SELECT user_login, user_pass, user_email, user_registered,
meta1.meta_value AS billing_address_1,
meta2.meta_value as billing_address_2,
meta3.meta_value as billing_city,
meta4.meta_value as billing_first_name,
meta5.meta_value as billing_last_name,
meta5.meta_value as billing_postcode,
meta5.meta_value as billing_country,
meta5.meta_value as billing_state
FROM wp_users users,
wp_usermeta meta1,
wp_usermeta meta2,
wp_usermeta meta3,
wp_usermeta meta4,
wp_usermeta meta5,
wp_usermeta meta6,
wp_usermeta meta7,
wp_usermeta meta8
WHERE users.id = meta1.user_id
    AND meta1.meta_key = 'billing_address_1'
AND users.id = meta2.user_id
    AND meta2.meta_key = 'billing_address_2'
AND users.id = meta3.user_id
    AND meta3.meta_key = 'billing_city'
AND users.id = meta4.user_id
    AND meta4.meta_key = 'billing_first_name'
AND users.id = meta5.user_id
    AND meta5.meta_key = 'billing_last_name'
AND users.id = meta6.user_id
    AND meta6.meta_key = 'billing_postcode'
AND users.id = meta7.user_id
    AND meta7.meta_key = 'billing_country'
AND users.id = meta8.user_id
    AND meta8.meta_key = 'billing_state'

However, at this point (and I haven't even listed half of the meta data that needs to be extracted), phpMyAdmin is telling me that my JOIN is too big ...

Is there a more efficient way of doing this?

  • 写回答

3条回答 默认 最新

  • drob50257447 2013-09-19 18:54
    关注

    If you need a user with all details then you can simply use get_userdata function as given below

    $user_info = get_userdata(1); // 1 is user ID here (required)
    echo 'Username: ' . $user_info->user_login . "
    ";
    echo 'User level: ' . $user_info->user_level . "
    ";
    echo 'User ID: ' . $user_info->ID . "
    ";
    // more...
    

    If you want to get the details of currently logged in user then you can use get_currentuserinfo function

    global $current_user;
    get_currentuserinfo();
    
    echo 'Username: ' . $current_user->user_login . "
    ";
    echo 'User email: ' . $current_user->user_email . "
    ";
    echo 'User first name: ' . $current_user->user_firstname . "
    ";
    echo 'User last name: ' . $current_user->user_lastname . "
    ";
    echo 'User display name: ' . $current_user->display_name . "
    ";
    echo 'User ID: ' . $current_user->ID . "
    ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器