Skip to main content
2 of 4
added 4 characters in body

Find all Users with a Custom Field Value in a Plugin

Spent a good amount of time trying to return all Users that match a custom field value.

Reading the docs here, it shows a findAll() command.

However, when trying the code below, it's not working.

use craft\elements\User;

$users = User::findAll(['customField' => $value]);

return count($users);  

The query doesn't fail, but rather, it times out. If I put in a non-valid custom field, an error is thrown.

Any ideas how to get a count of all Users that match a custom field value?