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

Käynnissä Julkaistu 5 vuotta sitten Maksettu toimituksen yhteydessä
Käynnissä Maksettu toimituksen yhteydessä

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 Tietojärjestelmäarkkitehtuuri WordPress

Projektin tunnus: #19053345

Tietoa projektista

3 ehdotusta Etäprojekti Aktiivinen 5 vuotta sitten

3 freelanceria on tarjonnut keskimäärin €29 tähän työhön

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 1 päivässä
(217 arvostelua)
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 1 päivässä
(253 arvostelua)
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 1 päivässä
(0 arvostelua)
0.0