admin管理员组文章数量:1431726
One of the plugins I am using generates user meta from our AD. One of the keys is the user's Manager.
As many users will have the same manager, I want to be able to group all users.
I was trying to find any way to do this, or adapt this post: getting all values for a custom field key (cross-post) but can't wrap my head around SQL database writing.
Practically, I want to be able to loop each meta manager with all the users that have that meta_value
with get_users
One of the plugins I am using generates user meta from our AD. One of the keys is the user's Manager.
As many users will have the same manager, I want to be able to group all users.
I was trying to find any way to do this, or adapt this post: getting all values for a custom field key (cross-post) but can't wrap my head around SQL database writing.
Practically, I want to be able to loop each meta manager with all the users that have that meta_value
with get_users
1 Answer
Reset to default 0Eventually came to a solution in case anyone needs it:
function mb_get_user_meta_values( $mb_user_meta_key ) {
if( empty($mb_user_meta_key) )
return;
$mb_get_users = get_users( array( 'meta_key' => $mb_user_meta_key ) );
$mb_user_meta_values = array();
foreach( $mb_get_users as $mb_user ) {
$mb_user_meta_values[] = get_user_meta( $mb_user->ID, $mb_user_meta_key, true );
}
$mb_user_meta_values = array_unique( $mb_user_meta_values );
return $mb_user_meta_values;
}
Then I can loop through the get_users
with the meta_value
本文标签: pluginsGet all user metakeys and then group users by matching values
版权声明:本文标题:plugins - Get all user meta_keys and then group users by matching values 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745573245a2664175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论