Write php code for wordpress to display user count by user role with shortcode

Pågående Publicerat 5 år sedan Betalades vid leverans
Pågående Betalades vid leverans

Hello,

I use wordpress with different user roles. I would like to be able to display via shortcode the user count per role. Can you write the php code that will allow me to use shortcode to display the number of users per definded role?

[user_count role="role_slug"]

I need to use the shortcode in the label of menue items, just in case this is important.

When doing some researche I found some code, but it displays only the count of all users, but maybe it might be helpful for you.

// Function to return user count

function wpb_user_count() {

$usercount = count_users();

$result = $usercount['total_users'];

return $result;

}

// Creating a shortcode to display user count

add_shortcode('user_count', 'wpb_user_count');

With kind regards

Matthias Reiter

HTML PHP Programvaruarkitektur WordPress

Projekt-id: #19053345

About the project

3 offerter Distansprojekt Aktivt 5 år sedan

3 frilansare har lagt bud på i genomsnitt €29 för det här jobbet

alyaspk

Hi, I am ready to create shortcode for user count with respect to user roles and assure 100% satisfaction guarantee. Looking forward to your fruitfully response. Regards Muhammad Alyas

€27 EUR inom 1 dag
(217 omdömen)
7.5
celalaybar

Hello. I can help you with writing necessary codes to get number of users with specific role by providing shortcode to be used. We can discuss further details on chat.

€30 EUR inom 1 dag
(253 omdömen)
7.4
shayanadesu

Hey, I can try my hands on it, as I guess I have an idea on how to achieve what you want. Let's discuss about it.

€30 EUR inom 1 dag
(0 omdömen)
0.0