admin管理员组文章数量:1287719
It's a really hectic day for me. Okay, I need to choose all users with some role, with and with some meta_data: subscriber, user_country, and user_sector for example.
In the beginning, I have several parameters: $role, $sector, $country Now I need to filter users by these parameters. At first, the task was to filter users by roles only. I did it this way:
$role = get_option('choosed_users_role'); //I get this from the database
$subscribers = get_users( $role );
$emails = array ();
foreach ( $subscribers as $subscriber ){
$emails[] = $subscriber->user_email;
}
This way I get all mail of the users with the specific role. When it became necessary to add two more parameters I thought that in this way I can add other parameters for filtering.
$subscribers = get_users( $role) && get_users( $sector) && get_users( user_country);
But it's not right I see now. What's the correct way to do this? Please help to figure out with it.
PS:
By advice Rup I tried using WP_User_Query:
$params = array(
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'user-country',
'value' => '17',
'type' => 'numeric',
),
array(
'key' => 'user-sector',
'value' => '602',
'type' => 'numeric',
)
)
);
But not the result. I think the WP_User_Query does not work because I try to get a custom ACF meta field.
本文标签: How to get metadata (in my case mail) of users who have a certain set of metadata
版权声明:本文标题:How to get metadata (in my case mail) of users who have a certain set of metadata? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741320291a2372164.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论