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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745573246a4633809.html
评论列表(0条)