最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

capabilities - How to query users to count all with a custom capability and limit it to a set of roles?

programmeradmin1浏览0评论

On a site with 12 custom user roles I need to count users with the 'supervisor' custom capability but limited to four specific roles.

The following code counts all users with the 'supervisor' capability, but does not limit it to the specific roles:

$args = array(
    'role'           => 'supervisor', //this is a custom capability
    'role__in' =>  array( 'level1', 'level2','level3','level4' ) //these are custom roles
    
);

$user_query = new WP_User_Query( $args );

$supervisors = count($user_query->results);
发布评论

评论列表(0)

  1. 暂无评论