The WP_User_Query generator tool allows you to easily generate custom queries to filter and display WordPress users based on a variety of criteria. This tool is perfect for site administrators and developers who need to retrieve user data for specific roles, metadata, or registration dates without manually writing SQL queries.
Use our AI-driven interface to craft complex user queries or select from preset options for rapid query generation.
Getting Started
Query Variable Name
my_user_query
Define a unique variable name for your query to prevent conflicts with other queries.
Role
Select the user role(s) to filter by (e.g., administrator
, subscriber
, editor
). The tool will include only users who belong to the selected role(s).
Number of Users
Specify how many users to retrieve in the query, such as the latest 10 users.
Order By
Choose how to order the users. Options include ID
, user_login
, display_name
, user_registered
, etc.
Order
Choose whether to sort users in ASC
(ascending) or DESC
(descending) order.
Meta Key
Enter the name of the custom field (user meta) you wish to filter by (e.g., last_login_date
).
Meta Value
Specify the value that the meta key should match (e.g., 2024-09-30
).
Compare
Choose a comparison operator to match the meta value, such as =
, !=
, >
, <
, or LIKE
.
$args = array(
'role' => 'subscriber',
'number' => 10,
'orderby' => 'user_registered',
'order' => 'DESC',
'meta_query' => array(
array(
'key' => 'last_login_date',
'value' => '2024-09-30',
'compare' => '='
),
),
);
$user_query = new WP_User_Query( $args );
Pro Tip: If you're dealing with large userbases, consider pagination to avoid performance issues when displaying results.
This tool simplifies the process of constructing complex queries without needing deep knowledge of WordPress's user query API. You can quickly generate user queries, saving time and avoiding errors.