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 1


Eventually 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) )

    $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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.