You can use the WP_User_Query
class, like the example below. Each code line have an small description, that you understand, what we do.
// Get all users with role Author.
$user_query = new WP_User_Query( array( 'role' => 'Author' ) );
// Get the total number of users for the current query. I use (int) only for sanitize.
$users_count = (int) $user_query->get_total();
// Echo a string and the value
echo 'So much authors: ' . $users_count;
Alternative you can also use the function get_users()
. But is only a wrapper for the query and have much more fields in the result.
Related Posts:
- Editor can create any new user except administrator
- Confirmation required on email change
- get_current_user_id() returns 0?
- Email user when password is reset by admin
- How to work around “that email address has already been used” error?
- How can I run a WP-CLI command as authenticated user?
- How to redirect a specific user after log-in?
- How to Prevent deleting user accounts in WordPress Back-end?
- LEFT JOIN, INNER OUTER JOIN, LEFT OUTER JOIN is driving me crazy. Please help?
- Upload gravatar in WP profile?
- How to stop a user from updating the post date
- Recover the user that have been deleted
- determining if the user is logged in
- Adding a photo to each WP user
- WordPress edit_user_profile_update update secondary role
- Check if user is online?
- Get all commenters on a post
- WP_User->add_role producing unexpected results
- Adding tags and inputs to a user’s profile
- Changing default Buddypress avatar affects all site avatars (because gravatar)
- Best way to have an per-user customized private section
- How to query users who have empty first_name?
- Post as someone else
- How to make user accept license agreement before download
- Does wp_delete_user() remove all user content?
- 14,000 WordPress Users. How did they get there?
- Adding second Email address for WP user notifications
- wp_login_form() passing user ID into URL on redirect?
- how to make a profile entry read only except for site managers [closed]
- Managing Users and Creating Groups [closed]
- Users: List A to Z, for Users
- Upgrade Nightmare – No Posts, Permissions Issues and Can’t Create a new post
- WPML Default Language User Meta [closed]
- Search Users base on meta_value & meta_key
- WordPress API for search
- Fix permissions for users role
- Redirect subscribers to last viewed page after log-in
- User Meta Data in a Sortable Table
- Are there mutiple ways to get usernames (as a hacker)
- How to stop redirect if user is already on correct page (Using Case Switch)
- search users using user name and user meta in wordpress
- Where are $current_user->allcaps set?
- How to activate the user search
- How change user type from contributor to author
- WordPress Login Customization for External Authentication
- How to allow registered users to submit the form only 5 times per day?
- Is there any action /filter hook I can use to disable login for some user role?
- Preventing user enumeration: which logic is better?
- Create a “user log”
- How can I do a url redirect to include a wordpress username?
- WP_User_Query combining role and ids
- WordPress current month users
- Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
- Can I Create a Second Admin Level User Role?
- Custom registration and pending approval
- Let logged-in users use radio buttons (yes and no) to exclude their author profile from the user listing
- Make new users automatically approved
- Adding fields to the “Add New User” but the form data not saved into DB
- Admin approval for editing user profile
- How would I restrict certain user levels from editing categories
- How can I set wp_dropdown_users so that it shows only authors?
- What does “link” refer to when you delete a user?
- WP Create User – Preventing repeated information
- Editor role can only create/edit/delete users who have one of two roles
- Can’t add user- wrong message “this user name is invalid because it uses illegal characters”
- set automatically email address for WordPress users
- WordPress 5.8 – Hide or Remove personal fields from admin Profile page
- Restricting wordpress login sessions for a web app
- change user password REST API
- Use WP cookie to authentificate user on an external app
- Find count of WordPress users by role and search string for user name
- Append USER ID to an outbound link?
- How do I add profile fields in specific section?
- Users activity history
- How to destroy all user sessions via WP-CLI
- Is a list of user names or IDs in a custom profile field the best way to create a followers list?
- How to restrict Admin from creating new users from Add new user screen in dashboard to only of one domain?
- Get meta key with value for user
- Redirect current user
- Display Users and user url’s
- custom login form, guide me
- is_user_logged_in() not working after domain change
- Get the author registration date in the header.php file
- Front end login and page restriction
- How i will get the images of highest scored users?
- Designing a member area on my site
- Link to Authors blog posts
- view and update form only for registered users
- Redirect based on log-in status per JavaScript
- i need to let a user to add a role from a frontend form
- Integrating Facebook Registration (and Login) on a WordPress page
- WordPress C# User Login
- Create users from frontend without password
- How to get user contact info
- Why does a super admin on multi site get a rest_user_invalid_id error code when requesting user details through REST?
- WordPress – Security Question at Login from User’s Meta Data
- determine active user browser at the same time
- get Discussion setting in wordpress
- Set a minimal number for next user_id
- Remove My Account Menu items in Woocommerce based on user roles