WP_User_Query Generator

Overview

Use this tool to create custom code for WordPress User Query with WP_User_Query class.

Usage

  • Fill in the user-friendly form.
  • Click the “Update Code” button.
  • Copy the code to your project.
  • Or save it as a snippet and share with the community.

Examples

If you are still learning how to use this tool, check out the following examples:

The variable used in the code.
Show The Loop.
Show users associated with certain role.
Show users associated with custom role.
Show specific list of users to be included.
Comma separated list of ID's. e.g. 1, 2, 3
Show specific list of users to be excluded.
Comma separated list of ID's. e.g. 4, 5, 6
Show users associated with certain blog on the network.
Number of users to show.
Number of users to displace or pass over.
Ascending or Descending order.
Sort retrieved users by.
Select from your saved WP_Meta_Query snippets.
Which users to query. Currently only "authors" is supported. Default is all users.
The total count of users found.
Set the fields you want to return.
Comma separated list of fields to return. e.g. id, user_login, user_nicename, user_email, user_url, user_registered
  Save Snippet
// WP_User_Query arguments
$args = array(
	'role'           => 'Administrator',
	'order'          => 'ASC',
	'orderby'        => 'display_name',
);

// The User Query
$user_query = new WP_User_Query( $args );