plugins - Get all user meta_keys and then group users by matching values

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

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

Share Improve this question asked Apr 19, 2019 at 7:27 markbmarkb 2996 silver badges18 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

相关推荐

  • plugins - Get all user meta_keys and then group users by matching values

    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

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信