You can use the “pre_user_query” filter hook to modify the query that retrieves the users.
Here’s an example code that how to sort the Users page admin column with an ACF field named.
function sort_users_by_acf_field( $query ) {
if ( ! is_admin() ) {
return;
}
if ( isset( $query->query_vars['orderby'] ) && 'user_company_name' === $query->query_vars['orderby'] ) {
$query->query_vars['meta_key'] = 'user_company_name';
$query->query_vars['orderby'] = 'meta_value';
}
}
add_action('pre_user_query','sort_users_by_acf_field');
Hope this will help!
Related Posts:
- How to order users alphabetically by their last name?
- ACF Upload Image in front-end with custom form
- Custom column sorting in WordPress admin post table
- User Last Login Sort Column
- Advanced Custom Fields: Sorting custom columns with custom fields sorts only by date
- Column Sorting Code on users.php
- Export Users and their Advanced Custom Fields
- Admin approval for editing user profile
- Advanced Custom Fields Plugin: how would I get an image src path uploaded from User Profile?
- Getting user data via ajax
- Post Taxonomy Value get from User Field Value
- meta_query orderby sort multiple keys
- How to order posts by the user_login that corresponds to a meta_value (which is a user id)?
- Find out if logged in user is not subscriber
- Get multiple roles with get_users
- How to Merge Two Authors Into One?
- Whats the best way to share user data across multiple WordPress websites?
- Delete all subscribers from wp_users and wp_usermeta a few thousand at a time
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- Allowing an email as the username?
- Get the name of user who updated post
- Disable delete user
- Display edit link if post author is current user
- Change user’s display name programmatically
- Do not allow users to create new posts and pages
- Send activation email to user after signup [duplicate]
- wp_update_user() does not update user_data
- Set user after wp_create_user?
- Sort get_users by custom field
- How to add follow functionality to multi-author wordpress site?
- Search multiple meta keys at once
- Get user input from a form
- Redirecting user after updating profile?
- How to add new custom field in default add user form through plugin
- How to add wordpress username after url?
- User fields that can be edited by administrator?
- Admins can’t edit each other’s posts
- Update user_login to change username
- Can I bulk register contributors for a new blog
- show cimy user fields in users.php with manage_users_columns
- Why i getting blank user_activation_key in get_user_by( ‘login’, $login ) function?
- how do i get a greeting for logged in uses by the time of day
- Can’t add users in admin after copying database
- How can i create an array user meta?
- Creating user in Firebase after WordPress user registration
- Exclude admin from user list
- Admin table list API?
- When I try to login in wordpress it is showing “USER Doesn’t Exists”
- Displaying different in-page content to cliente/admin
- Can i add password field into my wp registration form?
- how to get WordPress admin user table columns name in my plugin
- Limit a number of users returned from sorting users by latest posts function
- Will wordpress tools import do everything I need to copy one site to another
- Create Next and Previous Link to User orderby Last Name
- Accessing current users data within a plugin
- Spam users registers even when registration is disabled
- Limitations when adding new users
- User description only displayed for logged user
- Fetch all data of Users
- Get an array of all users of a custom role type to send an email notification on post update
- Sort a custom post with ACF: Date Picker & Display Featured!
- How to make Users sort in reverse order by default?
- How do you manage your pages or functions that require logged-in users?
- How to get ID of Edit User page during wp_handle_upload_prefilter, whilst in Media picker?
- What is correct way to change user’s email?
- Querying specific table row by current user login
- Get registered user’s country or IP
- How to make current user’s avatar + display name link to their profile?
- Import users once a day without a plugin
- Custom capability for a single user
- Allow Weak Passwords
- How do I modify the user role ‘subscriber’ to allow the user to delete posts
- delete_user_meta from a foreach results page
- Is it possible with a code snippet to display a green dot on top of every avatar on a WordPress site for each user that is online?
- How to display all user profile info in myaccount page wordpress
- Need to use WordPress page as authentication for different service
- wordpress Account Management generate password missing on my laptop
- Safely changing UserID’s, re-using deleted UserID’s and automatically using deleted userID’s instead of an increment
- How to make custom user profile page public?
- WP Query with meta queries
- Disable emails for new user registration
- Query for post term that matches user ID
- Change user URL
- User email verification without a plugin, is it possible?
- Deleting anonymous wp_users function not working?
- Add method for tracking who referred new users
- Resend user activation mail
- Cloning admin pages like users.php
- Changing user_login ends current session
- Does WordPress Need BuddyPress to Handle Large Amounts of Users?
- Using and saving custom dropdown boxes on user profiles
- Buddypress – New user type with no profile and can’t interact but can be admin of a group
- How to create front-end (editable) WordPress user profile pages?
- Securely log in a user without a password using a link?
- No one can edit post/pages by Administrator
- How to add custom detail page for a Subscriber at Admin Panel
- MySQL query to list users who never signed in
- Send email to user if their role is changed to Author
- sort by date in users