Skip to content

Improve get_users() Performance by Utilizing fields Argument #9781

@dilipbheda

Description

@dilipbheda

Enhancement Request

Currently, when using get_users() without specifying the fields argument, the function retrieves the full user object, including all associated user meta data. This can lead to unnecessary data fetching, especially when only specific fields like user IDs or emails are required. On large WordPress sites, this results in slower queries and higher memory usage.

Support for [fields] was added in WordPress 6.0. Since EDD now requires WordPress 6.2 or higher, we can safely use this feature.

Justification or use case

Enhance the get_users() function by encouraging or defaulting to the use of the fields argument where appropriate. This would allow developers to fetch only the necessary data, significantly improving query performance and reducing memory consumption.

// Fetch only user IDs for faster execution
$user_ids = get_users( array(
    'fields' => array( 'ID', 'user_login', 'etc...'' )
) );

Potential Benefits:

  • Reduced memory usage
  • Faster query execution
  • Improved scalability for large websites

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions