gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 13:34:48 25 4
gpt4 key购买 nike

这就是我能够将每个用户记录的所有相关数据提取到一行中的方法:

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'

但是,此时(我什至还没有列出需要提取的一半元数据),phpMyAdmin 告诉我我的 JOIN 太大了......

有没有更有效的方法来做到这一点?

最佳答案

如果您需要一个拥有所有详细信息的用户,那么您可以简单地使用 get_userdata函数如下所示

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

如果您想获取当前登录用户的详细信息,则可以使用 get_currentuserinfo功能

global $current_user;
get_currentuserinfo();

echo 'Username: ' . $current_user->user_login . "\n";
echo 'User email: ' . $current_user->user_email . "\n";
echo 'User first name: ' . $current_user->user_firstname . "\n";
echo 'User last name: ' . $current_user->user_lastname . "\n";
echo 'User display name: ' . $current_user->display_name . "\n";
echo 'User ID: ' . $current_user->ID . "\n";

关于php - WordPress:将 wp_users 和 wp_metadata 中的所有关联元数据选择到每个用户记录的一行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18902144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com