Skip to content

Instantly share code, notes, and snippets.

@sectsect
Last active February 12, 2016 10:14
Show Gist options
  • Save sectsect/9a415394ce0d2c340781 to your computer and use it in GitHub Desktop.
Save sectsect/9a415394ce0d2c340781 to your computer and use it in GitHub Desktop.
Remove "administrator" user from "get_users()" on wordpress.
<?php
function remove_administrator($users)
{
foreach ($users as $key => $user) {
$cap = reset($user->roles);
if ($cap === 'administrator') {
unset($users[$key]);
}
}
return $users;
}
?>
<?php
$users = get_users(array(
'orderby' => 'ID',
'order' => 'ASC'
));
$users = remove_administrator($users);
foreach ($users as $user):
?>
<a href="<?php echo get_author_posts_url($user->ID); ?>">
<?php $aID = get_the_author_meta('ID', $user->ID); ?>
<?php echo $user->display_name; ?>
</a>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment