Skip to content

Instantly share code, notes, and snippets.

@MatthieuScarset
Created July 16, 2015 07:35
Show Gist options
  • Save MatthieuScarset/162735b0796e82159e8f to your computer and use it in GitHub Desktop.
Save MatthieuScarset/162735b0796e82159e8f to your computer and use it in GitHub Desktop.
Drupal - Select and update all users by role
<?php
// Select and update user by role
$role = user_role_load_by_name('blogger');
$query = 'SELECT ur.uid FROM {users_roles} AS ur WHERE ur.rid = :rid';
$result = db_query($query, array(':rid' => $role->rid));
$uids = $result->fetchCol();
$users = user_load_multiple($uids);
foreach($users as $user) {
// $user->field_to_update['und'][0]['value'] = 1;
// user_save($user);
dpm($user);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment