Instead of a JOIN
, you can use a IN
with a subquery, to prevent duplicate results because of the join:
SELECT ID, display_name
FROM wp_users
WHERE ID IN (SELECT post_author FROM wp_posts)
This will not look at capabilities. If you also want that you can add them like a join, but move the meta_key
clause in the join, also to prevent duplicate results:
SELECT ID, display_name
FROM wp_users
JOIN wp_usermeta ON (wp_users.ID = wp_usermeta.user_id AND wp_usermeta.meta_key = 'wp_capabilities')
WHERE ID IN (SELECT post_author FROM wp_posts)
AND (wp_usermeta.meta_value LIKE '%"author"%'
OR wp_usermeta.meta_value LIKE '%"editor"%' )
Up to you to convert this back to PHP! Sidenote: Is the wp_
in wp_capabilities
dependent on the database prefix, or is it always wp_
, even if your table names start with another prefix?
Related Posts:
- If the current user is an administrator or editor
- Editor can create any new user except administrator
- Find out if logged in user is not subscriber
- Groups of capabilities: users with multiple roles?
- User-edit role setting distinct from wp_capabilities? [closed]
- Delete all subscribers from wp_users and wp_usermeta a few thousand at a time
- Execute a function when admin changes the user role
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- Hide Admin Menu for Specific User ID who has administrator Role
- Grouping users under parent user
- How to update user role without logout
- Do not allow users to create new posts and pages
- How can I add a user through SQL?
- How to enable the theme editor cap for an editor role?
- How to assign capabilities to user NOT to User Role
- How to assign an additional/extra/second user-role to multiple users (of a specific user-role)
- How to stop a user from updating the post date
- importing users where password is provided as md5 + much metadata
- Search multiple meta keys at once
- WordPress edit_user_profile_update update secondary role
- wp_insert_user is not working for me?
- How to customize wp_signon()
- Is there a simple way to manage capabilities per user?
- Is it possible to get a user with just the password field?
- How to get the Role Name of the current user? (WordPress)
- set_role has no effect
- WP_User->add_role producing unexpected results
- SQL User Query by Multiple Roles using PHP
- Users roles, make a page belonging to multiple users
- Redirect after users complete profile form
- How do I list in the backend all users that were assigned to a custom role?
- How to add local users to wordpress without email password?
- Getting users by specific capability, not role
- Add user data to table when user is created?
- Managing Users and Creating Groups [closed]
- How to disable a specific page for a specific user
- Are User Levels Still Currently Used?
- Error: How to allow the “contributor” to upload media in wordpress
- Remove Capabilities from WP admin for specific user role
- wordpress user roles are not working
- Displaying different in-page content to cliente/admin
- Fix permissions for users role
- User capability for editing their own comments
- What are some best practices for user exit strategy?
- Is there a way to identify a user in a custom REST API method? [duplicate]
- Problem with automatic role change through cron job
- Allow Contributors to Upload Files
- How can I allow an User to publish only 5 posts per month?
- Is possible to allow user to login with different role?
- I am getting mysql_real_escape_string() function error while adding user?
- Where are $current_user->allcaps set?
- How change user type from contributor to author
- How do I let contributors edit their posts after being approved once?
- create new users in db starting at what ID?
- Delete Users without a First and Last Name
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Load user by specific role
- What’s the correct way to add capabilites to user roles?
- Fix ‘Add Role’ Option not there in wordpress 5.2.2
- User roles not displaying
- Allow admins to login as other users
- Allow Users to Modify Some Values of Assigned WordPress Pods [closed]
- Can I Create a Second Admin Level User Role?
- Customising “user ids” and add to ‘user’ panel in the admin area
- Assigning multiple or additional capabilities to specific users or how to create additional roles like bbpress roles?
- Change User Role based on Point System Issue
- How do I modify the user role ‘subscriber’ to allow the user to delete posts
- Editor role can only create/edit/delete users who have one of two roles
- Delete all users with Editor role and their content mysql
- Update user role for expired membership
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- How to hide “Change role to” dropdown on Users admin menu
- Find count of WordPress users by role and search string for user name
- hide page menu from admin panel for specific users
- fine-grained capabilities for user related capabilities
- Disabling user capability to edit_posts or delete_posts in the front-end
- In admin manage users page, how can I stop users with certain privileges from editing users with other privileges?
- User Role not showing in Users Screen
- Groups roles & capabilities
- Custom User Role: Can Edit Own Page, Cannot Create New
- Button for users to upgrade their user role + Button to show current user role!
- Allowing users to edit only their page and nobody else’s
- How to bulk change user role to “No role for this site”
- Access level seems to have gone from admin to editor
- Restrict Access to the User Profile
- Subscriber role – blank page
- is_user_logged_in() not working after domain change
- How to get only 1 role from user
- Front end login and page restriction
- User “none” role
- Giving users an editable homepage/business directory
- i need to let a user to add a role from a frontend form
- Limit user access to installing/configuring a plugin?
- Increase by one the user counter on specific role
- Show only users with the same role in Dashboard user list
- MySQL query to list users who never signed in
- Send email to user if their role is changed to Author
- Remove My Account Menu items in Woocommerce based on user roles
- WordPress: New user role which is ONLY allowed to manage media