These are examples of queries to fetch user data and log the user in.

Fetching users permalink

A single user with his/her posts:

A list of 5 users, ordered by name:

A list of predefined users, with their avatars:

Filtering users by name:

Counting user results:

Paginating users:

Fetching meta values:

Fetching roles and capabilities permalink

⚠️ Note: Read more in guide Querying “sensitive” data fields.

Getting the roles and capabilities for the users:

Logging the user in and out permalink

Logging the user in is required to execute mutations (create a post, add a comment, etc).

This query logs the user in (execute it to log in to the demo site, using a test account with role subscriber):

To retrieve the logged-in user:

Log the user out: