First, use $query->query_vars
and not $query->query
.
Secondly, you should run this conditional check before overriding the corresponding query var:
empty( $_REQUEST['{VAR}'] ) || !isset($query->query_vars['{VAR}'])
where {VAR}
corresponds to the query var’s name/key such as orderby
.
So try this, which worked for me:
// Set default `orderby` to 'registered'.
if( empty( $_REQUEST['orderby'] ) || !isset($query->query_vars['orderby']) ) {
$query->set('orderby', 'registered');
}
// Set default `order` to 'DESC'.
if( empty( $_REQUEST['order'] ) || !isset($query->query_vars['order']) ) {
$query->set('order', 'DESC');
}
which you would use in place of:
if( !isset($query->query['orderby']) ) {
$query->set('orderby', 'registered');
$query->set('order', 'DESC');
}
Related Posts:
- Searchable meta value in user.php
- Can’t add users in admin after copying database
- Displaying different in-page content to cliente/admin
- Are there mutiple ways to get usernames (as a hacker)
- New user form rejected because “passwords don’t match”—but there’s only one password field
- WordPress Password security related questions
- Allow admins to login as other users
- wp-admin/users.php Add a column with last name
- Is nicename the same as nickname in WP?
- wordpress Account Management generate password missing on my laptop
- How do I delete a wordpress user from giant database?
- If the current user is an administrator or editor
- Editor can create any new user except administrator
- How do I add a field on the Users profile? For example, country, age etc
- How do I display logged-in username IF logged-in?
- Admin Page Redirect
- How to allow an user role to create a new user under a role which lower than his level only?
- user_login vs. user_nicename
- How to programatically change username (user_login)?
- Change the Author Slug from Username to Nickname
- Remove Ability for Other Users to View Administrator in User List?
- Difference between update_user_meta and update_user_option
- Make display name unique
- Make WooCommerce pages accessible for logged in users only
- Find out if logged in user is not subscriber
- WordPress usermeta scaling for thousands of users
- How to get WordPress Username in Array format
- Display user registration date
- Setting admin edit panels & metaboxes positions and visibility for ALL users and admins
- Get multiple roles with get_users
- Showing User’s Post Counts by Custom Post Type in the Admin’s User List?
- get_user_meta() doesn’t include user email?
- Update post counts (published, draft, unattached) in admin interface
- Confirmation required on email change
- How to Merge Two Authors Into One?
- Whats the best way to share user data across multiple WordPress websites?
- get_current_user_id() returns 0?
- How to get userid at wp_logout action hook?
- Groups of capabilities: users with multiple roles?
- Is there a way to merge two users?
- User-edit role setting distinct from wp_capabilities? [closed]
- List users by last name in WP_User_Query
- What’s the difference between the capability remove_users and delete_users?
- How to restrict access to uploaded files?
- How to save dismissable notice state in WP 4.2?
- Automatically delete inactive users after 2 months
- How to change user_login with wp-cli?
- Delete all subscribers from wp_users and wp_usermeta a few thousand at a time
- Email user when password is reset by admin
- Replacing the WordPress password validation
- Ban a user and end their session
- Allowing users to edit only their page and nobody else’s
- How can 2 blogs share the same users
- alphabetically order role drop-down selection in dashboard
- Can an admin check passwords of registered users?
- WordPress auto login after registration not working
- WordPress Multisite allow site admin to add user without email confirmation
- Change the author slug from nickname to ID
- Execute a function when admin changes the user role
- How to let contributors to create a new revision(draft) editing their published posts
- how to use joomla password format in wordpress?
- How to obtain the user ID of the current profile being edited in WP-Admin?
- How to do get_users() with multiple meta_keys
- Disallowing Users of a Custom Role from Deleting or Adding Administrators?
- What the user_status column?
- How to limit users to one comment per post
- Different back-end language for different users?
- Hide Admin Menu for Specific User ID who has administrator Role
- Migrating WordPress users into Disqus
- Problem with Hebrew characters in username
- Is there an upper limit for users in WP?
- How to display the status of users (online – offline) in archive.php
- Remove email verification when new user register
- How to change user`s avatar?
- How to set up User email verification after Signup?
- Allow up to 5 Concurrent Login Sessions
- How to let user set password on registration
- How to hide media uploads by other users in the Media menu?
- Show admin bar only for some USERS roles
- How to display custom user meta from registration in backend?
- Allowing an email as the username?
- How to work around “that email address has already been used” error?
- Get the name of user who updated post
- Disable delete user
- Grouping users under parent user
- How to get the Gravityform entry ID from current user’s form submission? [closed]
- Retrieve all users from wordpress database via REST/JSON API
- Is there a way to set a user profile to Draft?
- Display edit link if post author is current user
- Check if specific username is logged in
- Best way to send users password?
- Limiting the number of users
- How can I get users email (and additional data) from the rest API?
- Force display name as full name
- Get users with atleast one post
- edit profile validation refreshes all field if missing wordpress
- How to update user role without logout
- 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 order users alphabetically by their last name?