Try this:
function profile_counts($atts) {
$atts = shortcode_atts( array(
'metakey' => '',
'metavalue' => '',
'userrole' => '',
), $atts );
$user_ids = get_users( array(
'meta_key' => $atts['metakey'],
'meta_value' => $atts['metavalue'],
'role__in' => wp_parse_list( $atts['userrole'] ),
'fields' => 'ID', // retrieve just the IDs
'count_total' => false, // no need for FOUND_ROWS()
) );
return count( $user_ids );
}
Important points:
-
For multiple roles, you can use the
role__in
parameter. -
You only need to call
shortcode_atts()
once.
Related Posts:
- Display current user metadata on WordPress page
- How to manually fix the WordPress gallery code using PHP in functions.php?
- Create a global variable for use in all templates
- Shortcode putting html such as
- Can i check if user is doing any ajax request?
- Counting number of posts in a category and its sub categories and displaying result using shortcode
- Shortcode created to check language not works
- Add/echo div with Analytics-Code to function in functions.php
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- WordPress menu deletes when trying to add a hook
- Wrap each shortcode in array to div
- Recent post display using shortcode
- Nested shortCode functions in the functions.php file
- Making Quote Plugin more efficient
- Placing raw HTML inside a WordPress shortcode
- Shortcode content output but not in correct place
- PHP code inside shortcodes
- Shortcode content filter?
- Trigger popup in a php if/else statement
- How to output a PHP file values by shortcode?
- Showing content from one page on another
- How to display posts by current user in a drop down
- Get value from shortcode to do something
- How to retrieve current wordpress profile page URL?
- Modify user profile data through scripting?
- Custom shortcode outputs plain text instead of HTML at top of post
- Get users that likes the post
- Pass php dynamic variable to shortcode
- How to Reference/Echo Variable from Another PHP Function
- Remove echo from shortcode
- Call to undefined function get_userdata() in plugin
- Shortcode with PHP issue “Undefined index”
- Shortcode from a function not working
- Display Data in Table from External Database in WP using Shortcodes
- Is it possible to return content, and then also continue to do other things?
- ::before on open/close function [closed]
- Is it possible to define variables in a wordpress shortcode, and then call the shortcode using a specific variable?
- Creating WordPress Shortcode with Variable
- Shortcode to find and replace URL
- Help with WordPress function inside a shortcode
- calling a custom field value inside functions.php
- List all blogs, but exclude the main site
- Shortcode to embed Edit Account form not working
- Shortcode for Listing Users from Meta Value?
- Cant display an image via PHP in wordpress
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- php return username of currently viewed author profile
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- AJAX function not working [closed]
- Customize field names in backend profile edit page through function.php [duplicate]
- Use of antispambot with $curauth->email
- Uses for function: wp_update_user
- Updating Metadata with Shortcode
- Generate a QR code when creating a new WordPress user
- Display logged in user name and lastname on page
- Change wordpress’ database data using ajax – how to get current user id?
- Create shortcode for metabox gallery
- Allow a user or role to view drafts and previews, but not other admin privileges?
- Display Visual Composer shortcode if a post belongs in specific categories
- Why is the current page loaded in the pop-up window and not the specified one?
- How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
- Block error message in foreach loop when looping through ACF field
- Get current user id in function php
- How can I prevent a shortcode div from extending beyond its boundaries?
- PHP multiple forms, same page, isset($_POST[]) not working?
- Gravity Forms: How to add PHP function to confirmation conditional shortcode?
- wpdb->query returns different value to phpMyAdmin
- shortcodes, custom php and their errors
- Display a custom name when the user has no name settle in his account
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- Reload page with a different shortcode when a user selects from a dropdown
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Offset with ajax load more posts duplicates
- Get posts by id using shortcode
- Add another role to a user when they click a button?
- Shortcode’s output to use as other shortcode’s parameter
- Open/closed function [closed]
- Need to Echo A Url path to show on a wordpress page
- Can’t get_users info by using json_encode
- Wrapping shortcode content in a span or link
- Matching multi user
- Need help with PHP functions
- Private messaging – Getting and displaying the avatar/url of a message recipient
- main menu page redirects to user ID
- How to have Function of a plugin using global vars into a shortcode?
- Get author meta of all writers
- Overwriting a Shortcode
- Shortcoding with Divs
- WordPress display name string manipulation
- Display a list of users with avatar filterable with alphabets
- My title is showing after the shortcode
- A next page function with shortcode?
- Shortcode to include PHP file, pass various parameters to include?
- WP Custom tables query
- Display terms on product page with shotrcode
- How call WordPress shortcode inside function file
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- Custom Admin Menu Report for Specific User ID