admin管理员组文章数量:1335380
i want to display in my Home page total user count by specific role in WordPress as statistics
I already created Role (subscriber, contributor) and i want to show the total users for each of those roles.
Can You Please point me also with the answer where i can put the code ?
i want to display in my Home page total user count by specific role in WordPress as statistics
I already created Role (subscriber, contributor) and i want to show the total users for each of those roles.
Can You Please point me also with the answer where i can put the code ?
Share Improve this question asked Jul 24, 2020 at 18:39 Adnan OmarAdnan Omar 114 bronze badges2 Answers
Reset to default 0insert this code in your theme functions.php and use this shortcode [users_count_bro] to display where you want
function total_count_bro() {
$out = '';
$user_count_data = count_users();
$avail_roles = $user_count_data['avail_roles'];
foreach ( $avail_roles as $role_key => $role_count ) {
$out .= $role_key.':'.$role_count.'<br/>';
}
return $out;
}
add_shortcode( 'users_count_bro', 'total_count_bro' );
I manage to do it like this:
/* user count */
// Function to return user count 1
function total_count_bro() {
$out = '';
$user_count_data = count_users();
$avail_roles = $user_count_data['avail_roles'];
foreach ( $avail_roles as $role_key => $role_count ) {
$out = $contributor = $avail_roles['contributor']; /* User role author */'<br/>';
}
return $out;
}
add_shortcode( 'users_count_bro', 'total_count_bro' );
// Function to return user count 2
function total_count_bro2() {
$out = '';
$user_count_data = count_users();
$avail_roles = $user_count_data['avail_roles'];
foreach ( $avail_roles as $role_key => $role_count ) {
$out = $subscriber = $avail_roles['subscriber']; /* User role administrator */'<br/>';
}
return $out;
}
add_shortcode( 'users_count_bro2', 'total_count_bro2' );
This will create the total count for the user by role and it will show the number count only.
本文标签: shortcodeHow to display total user count by specific role in WordPress as statistics
版权声明:本文标题:shortcode - How to display total user count by specific role in WordPress as statistics? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742232619a2437498.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论