[英]WordPress get_users() by role only returning those that have the role, plus another
[英]Wordpress get_users() returning all users with a compare query
我似乎無法弄清楚為什么所有用戶都會收到此查詢。 任何幫助,將不勝感激。
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-key => meta-value比較來吸引用戶。 因此,您需要使用以下meta_queries
:-
$args = array(
'meta_query' => array(
'key' => 'profilepicture',
'value' => '3',
'compare' => '='
)
);
$users = get_users( $args );
您必須使用包含一個或多個數組的meta_query
。 您也可以嘗試以下操作。
$meta_query = new WP_Meta_Query();
$meta_query->parse_query_vars( array(
'meta_key' => 'profilepicture',
'meta_value' => '3',
'meta_compare' => '='
) );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.