AnswerBun.com

How to display total user count by specific role in WordPress as statistics?

WordPress Development Asked by Adnan Omar on January 2, 2022

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 ?

2 Answers

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.

Answered by Adnan Omar on January 2, 2022

insert 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' );

Answered by Sergei on January 2, 2022

Add your own answers!

Related Questions

WordPress Importer “Failed to import Media”

0  Asked on January 19, 2021 by orbita

 

Override theme file from plugin

0  Asked on January 18, 2021 by toma-tomov

 

Why can I not view image attachment pages?

3  Asked on January 17, 2021 by h-hall

     

Image color changes in wordpress

0  Asked on January 16, 2021 by giulia

     

Inserting additional   into menu item text

2  Asked on January 16, 2021 by marsandback

 

wp_mail() not sending emails with ajax

2  Asked on January 16, 2021 by mohd-hasan

   

How to ignore fields if empty?

1  Asked on January 16, 2021 by israel-santiago

   

Change WordPress post-state in Admin Area

2  Asked on January 16, 2021 by gino

   

Select posts with any post_type from database?

1  Asked on January 15, 2021 by lisandro-vaccaro

 

Why does WP_Post not contain its permalink?

3  Asked on January 14, 2021 by dodov

   

How to check post type when using sanitize_title hook?

1  Asked on January 14, 2021 by michael-rogers

 

WordPress retrieve media except cropped

0  Asked on January 12, 2021 by adviner

 

You have an error in your SQL syntax – Help with query

2  Asked on January 11, 2021 by ogmios

   

Is it possible to display tag cloud widget by category?

1  Asked on January 11, 2021 by taller-de-wordpress

   

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP