User Queries
Query WordPress users for author pages, team listings, and user-related content displays.
What This Guide Covers
Users are essential for author pages, team sections, contributor listings, and user-based content filtering. This guide shows you how to query WordPress users using Builderius GraphQL for any user-related scenario.
You'll learn how to:
- Get current user data for logged-in user templates
- Query multiple users for team pages and author listings
- Filter users by roles, search terms, and user IDs
- Access custom user fields from ACF
- Build user-based content relationships
- Handle user pagination and ordering
Query Single User
- Current User
- Specific User
Get the currently logged-in user:
{
current_user {
ID
display_name
user_email
avatar_url
roles
}
}
Get a user by ID, slug, email or login:
{
# Query by user ID (default identifier)
user(identifier: "ID", value: 123) { # Int - User ID number
display_name
user_email
}
# Query by user slug
user(identifier: "slug", value: "john-doe") { # String - User slug/nicename
display_name
user_email
}
# Query by user email
user(identifier: "email", value: "[email protected]") { # String - User email address
display_name
user_email
}
# Query by user login
user(identifier: "login", value: "johndoe") { # String - Username/login
display_name
user_email
}
}
Complete User Fields Reference
Here's what's available when querying a user - all standard WordPress user fields plus custom field integrations:
{
user {
# Basic Fields
ID
user_login
user_email
user_url
display_name
nickname
first_name
last_name
description
avatar_url
# User Roles and Capabilities
roles
capabilities
# Custom Meta Fields
meta_value(key: "custom_meta_key")
# ACF Fields
job_title: acf_value(name: "job_title")
bio: acf_value(name: "bio")
social_links: acf_value(name: "social_links")
department: acf_value(name: "department")
phone: acf_value(name: "phone")
}
}
Basic User Loop
{
users_query (
arguments: {
exclude: [0]
}
) {
users {
nickname
user_email
display_name
avatar_url
}
}
}
Query Arguments
Complete Arguments Reference
All arguments available for users_query Pro feature
{
users_query(
arguments: {
# Role Filtering
role: "editor" # String - Filter by user role (administrator, editor, author, contributor, subscriber)
# Include/Exclude Users
include: [1, 5, 12] # Array - Include only these user IDs
exclude: [3, 7] # Array - Exclude these user IDs
# Search & Filtering
search: "john" # String - Search term
search_columns: ["nickname", "user_email"] # Array - Search columns (display_name, user_login, user_email, user_url, user_nicename, nickname)
# Pagination & Limits
number: 20 # Int - Number of users to return
offset: 5 # Int - Number of users to skip from start
# Ordering
orderby: "display_name" # String - Sort field (display_name, user_login, user_email, user_registered, user_nicename, user_url)
order: "ASC" # String - Sort direction (ASC, DESC)
}
) {
users {
display_name
}
}
}
Basic Filtering
- By Role
- Search Terms
- Ordering
- Include/Exclude
Filter by user roles:
{
users_query(
arguments: {
role: "editor" # Specific role
}
) {
users {
display_name
roles
}
}
}
Search users by name, email, or username:
{
users_query(
arguments: {
search: "smith" # Search term
search_columns: ["nickname", "user_email"]
}
) {
users {
display_name
user_email
user_login
}
}
}
Control user order and sorting:
{
users_query(
arguments: {
orderby: "display_name" # display_name, user_login, user_email, etc.
order: "ASC" # ASC, DESC
}
) {
users {
display_name
user_email
}
}
}
Include or exclude specific users:
{
users_query(
arguments: {
include: [1, 5, 12] # Only these users
exclude: [2, 8] # Exclude these users
}
) {
users {
display_name
}
}
}
Access Custom Fields
Query custom fields from ACF or native WordPress user meta fields.
- ACF Fields
- Native Meta
- Combined Data
Access Advanced Custom Fields data:
{
users_query(
arguments: {
role: "author"
number: 10
}
) {
users {
display_name
avatar_url
job_title: acf_value(name: "job_title")
department: acf_value(name: "department")
bio: acf_value(name: "bio")
social_links: acf_value(name: "social_links")
}
}
}
Access native WordPress user meta fields:
{
users_query(
arguments: {
number: 10
}
) {
users {
display_name
first_name: meta_value(key: "first_name")
last_name: meta_value(key: "last_name")
nickname: meta_value(key: "nickname")
}
}
}
Combine ACF fields with native data:
{
user(identifier: "ID", value: 5) {
display_name
user_email
avatar_url
roles
description
# Native meta fields
first_name: meta_value(key: "first_name")
last_name: meta_value(key: "last_name")
# ACF fields
job_title: acf_value(name: "job_title")
department: acf_value(name: "department")
phone: acf_value(name: "phone")
linkedin: acf_value(name: "linkedin_url")
}
}
Related Content Patterns
Find content related to users, such as posts by specific authors or user relationships.
- User Posts
- Current User Posts
- Team by Department
Get posts authored by a specific user:
{
user(identifier: "ID", value: 5) {
ID @private # Get user ID privately
display_name
avatar_url
description
user_posts: posts_query(
arguments: {
author: "{{ID}}" # Posts by this user
posts_per_page: 10
post_status: "publish"
orderby: "date"
order: "DESC"
}
) {
posts {
post_title
post_excerpt
post_date
permalink
}
}
}
}
Get posts by the currently logged-in user:
{
current_user {
ID @private # Current user ID
display_name
avatar_url
my_posts: posts_query(
arguments: {
author: "{{ID}}" # Current user's posts
posts_per_page: 10
post_status: "publish"
orderby: "date"
order: "DESC"
}
) {
posts {
post_title
post_status
post_date
permalink
}
}
}
}
Get users from the same department (using ACF field):
{
user(identifier: "ID", value: 5) {
ID @private # Current user ID
display_name
department: acf_value(name: "department") @private
colleagues: users_query(
arguments: {
number: 10
exclude: "{{ID}}" # Exclude current user
orderby: "display_name"
order: "ASC"
}
) {
users {
display_name
avatar_url
user_email
department: acf_value(name: "department")
job_title: acf_value(name: "job_title")
}
}
}
}
Pagination
Handle pagination for user listings with custom URL parameters.
- Basic Pagination
- Advanced Pagination
Basic user pagination:
{
users_query(
arguments: {
role: "author"
number: 12
orderby: "display_name"
order: "ASC"
}
) {
users {
display_name
avatar_url
description
}
pagination(
arguments: {
pagination_url_param_name: "authors_page"
}
) {
links
current_page
total_pages
}
}
}
Advanced pagination with offset and custom ordering. This pagination adds expression_result to automatically create formatted text like "2 of 5 pages" instead of requiring you to manually combine the current_page and total_pages values in your template.
{
users_query(
arguments: {
role: "contributor"
number: 20
offset: 0 # Starting point
orderby: "display_name"
order: "ASC"
}
) {
users {
display_name
user_email
avatar_url
roles
}
pagination(
arguments: {
pagination_url_param_name: "team_page"
}
) {
current_page
total_pages
links
# Enhanced pagination info
page_info: expression_result(
expression: "current_page . ' of ' . total_pages . ' pages'"
)
}
}
}
Performance Tips
Optimize your user queries for better performance by using these techniques.
- Use @private Fields
- Limit Data
- Efficient Ordering
Use @private to query data you need for variables but don't want in output:
{
current_user {
ID @private # Hidden from output, available for {{ID}}
display_name
department: acf_value(name: "department") @private
colleagues: users_query(
arguments: {
exclude: ["{{ID}}"] # Uses private ID
number: 5
}
) {
users {
display_name
# Filter by department using private field would require additional logic
}
}
}
}
Only fetch the fields and users you actually need:
{
users_query(
arguments: {
number: 10 # Don't fetch more than needed
role: "author" # Filter by role
orderby: "display_name"
order: "ASC"
}
) {
users {
display_name # Only fields you'll use
avatar_url
description
}
}
}
Use efficient ordering methods:
{
users_query(
arguments: {
orderby: "display_name" # Efficient: display_name, user_login
order: "ASC"
number: 15
}
) {
users {
display_name
user_email
}
}
}
Common Use Cases
Real-world examples of user queries you'll commonly need for team pages, author listings, and user-based content.
- Team Page
- Author Bio
- Contributors
Team members page with roles and departments:
{
users_query(
arguments: {
role: "editor" # Team member role
number: 20
orderby: "display_name"
order: "ASC"
}
) {
users {
display_name
user_email
avatar_url
description # WordPress bio field
roles
# ACF fields for team info
job_title: acf_value(name: "job_title")
department: acf_value(name: "department")
phone: acf_value(name: "phone")
linkedin: acf_value(name: "linkedin_url")
}
}
}
Author bio with recent posts:
{
user(identifier: "ID", value: 5) {
ID @private # Author ID
display_name
user_email
avatar_url
user_url # Author website
description # WordPress bio field
roles
# ACF fields for extended bio
bio: acf_value(name: "extended_bio")
social_links: acf_value(name: "social_links")
# Recent posts by this author
recent_posts: posts_query(
arguments: {
author: "{{ID}}" # Posts by this author
posts_per_page: 5
post_status: "publish"
orderby: "date"
order: "DESC"
}
) {
posts {
post_title
post_excerpt
post_date
permalink
featured_image {
file_url(size: THUMBNAIL) # Small images for author page
alt_text
}
}
}
}
}
Contributors list with search and filtering:
{
users_query(
arguments: {
search: "developer" # Search in user fields
number: 15 # Limit results
orderby: "display_name" # Alphabetical order
order: "ASC"
}
) {
users {
display_name
user_email
avatar_url
description # User bio
roles
# Get their most recent contribution
latest_post: posts_query(
arguments: {
author: "{{ID}}"
posts_per_page: 1
post_status: "publish"
orderby: "date"
order: "DESC"
}
) {
posts {
post_title
post_date
permalink
}
}
}
pagination(
arguments: {
pagination_url_param_name: "contributors_page"
}
) {
links
}
}
}