WordPress The Right Way
English en-US
English en-US
  • WordPress The Right Way
  • Getting Started
  • Debugging
    • Error Logging
    • Handling Errors
    • Tools
    • Constants of wp-config.php
  • Data
  • Core
  • Code Style Guide
  • I18n
  • JavaScript
  • Multisite
  • Queries
    • User Queries
    • SQL
    • Taxonomy and Term Queries
    • Comment Queries
    • Post Queries
  • Routing
    • The Main Loop & Template Loading
    • What Are Query Variables and Where Do They Come From?
    • Clashes, Slugs, & Debugging
    • Rewrite Rules
  • Security
    • Secure HTTP
    • Standalone PHP Files
  • Servers And Deployment
    • Migrations
    • WP CLI
  • Templates
  • Testing
    • Testing Theory
      • Test Driven Development
      • Unit Testing
      • Behavior Driven Development
    • Testing Plugins
    • WP_UnitTestCase
  • Widgets
  • Community
  • Credits
Powered by GitBook
On this page
  1. Queries

User Queries

Similar to comment queries, user queries can be used to find individual users, users with specific roles, and other parameters.

Here is a basic User query:

$args = array(
    //
);

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

// User Loop
if ( ! empty( $user_query->results ) ) {
    foreach ( $user_query->results as $user ) {
        echo '<p>' . $user->display_name . '</p>';
    }
} else {
    echo 'No users found.';
}

Note that the user query class may not be available yet if your code runs very early.

PreviousQueriesNextSQL

Last updated 4 years ago