Get user role by user field
Similar to this question:

I have an user field called "custField" and it's value (example : 123456). I need to check all users that have "123456" as value:

$users = \Drupal::entityTypeManager()-&gt;getStorage('user')
  -&gt;loadByProperties(['field_custField' =&gt; '123456']);


Then, I need to check if this user:

$user = reset($users);


has the role "director":

$user_has_role = $user &amp;&amp; $user-&gt;hasRole('director');