gpt4 book ai didi

php - Wordpress get_users() 通过比较查询返回所有用户

转载 作者:行者123 更新时间:2023-12-04 05:39:51 25 4
gpt4 key购买 nike

我似乎无法弄清楚为什么所有用户都会通过此查询返回。任何帮助将不胜感激。

function user_main(){

$args = array(
'meta_key' => 'profilepicture',
'meta_value' => '3',
'meta_compare' => '='
);

$query = new WP_Query( $args );

$blogusers = get_users( $query );

// Array of WP_User objects.

foreach ( $blogusers as $user ) {

$current_meta = get_user_meta($user->ID, 'profilepicture', true);
write_log($user->ID . ' ' . $current_meta);
}

}

最佳答案

因为您正在尝试根据元键=>元值比较来获取用户。因此,您需要使用 meta_queries ,如下所示:-

$args = array(
'meta_query' => array(
'key' => 'profilepicture',
'value' => '3',
'compare' => '='
)
);

$users = get_users( $args );

关于php - Wordpress get_users() 通过比较查询返回所有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45229101/

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