WP_User_Query has an ‘exclude’ argument, which is designed to accept an array of user IDs to exclude. Since it will accept an empty array, when that’s the only parameter, the resulting object will contain all registered users. The most direct path to the IDs is via the $results property.
We can reduce $results to just user IDs, using wp_list_pluck() as shown below:
$user_query = new WP_User_Query( array( 'exclude' => array( ) ));
if ( ! empty( $user_query->results ) ) {
$ids = wp_list_pluck( $user_query->results, 'ID' );
}
The variable $ids, now contains the IDs of all registered users.
Related Posts:
- How do I display logged-in username IF logged-in?
- Difference between update_user_meta and update_user_option
- Make display name unique
- How to get WordPress Username in Array format
- Display user registration date
- How to set up User email verification after Signup?
- Allow up to 5 Concurrent Login Sessions
- How can I get users email (and additional data) from the rest API?
- How to hide “Filter user list” from “All Users” screen
- How to create a template for a custom URI associated with the user
- How to check user role without using current_user_can()
- How to assign capabilities to user NOT to User Role
- Setting WP Admin passwords to expire
- How do i auto approve new user?
- BuddyPress | Check if user is in current group [closed]
- Pre-populate Username Field
- Where to Store Custom User Fields
- Redirect after User Activation [closed]
- Getting users who registered 360 days from current date
- Querying Email Addresses for a List of Users with Same Last Name?
- How to keep track of user logins?
- Mass delete spam accounts
- 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)
- Custom style on profile options page
- 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
- Max no of simultaneous active sessions for a single user
- WPML Default Language User Meta [closed]
- Search Users base on meta_value & meta_key
- Favorite taxonomy archive page?
- 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)
- Rest api return all users (even without content) to all users
- Column Sorting Code on users.php
- How can I allow an User to publish only 5 posts per month?
- 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
- Using a custom field value as current users name [closed]
- How would I restrict certain user levels from editing categories
- How can I set wp_dropdown_users so that it shows only authors?
- 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
- hide user is currently editing warning in admin post 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?
- fine-grained capabilities for user related capabilities
- 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?
- Custom User Role: Can Edit Own Page, Cannot Create New
- 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
- Edit dashboard based on user ID
- is_user_logged_in() not working after domain change
- Modify Profile Biographical Info Field
- Problem with update_user_meta() meta_value