Specifying multiple user roles with PHP
-
I found this code, and it’s showing all of the users, even subscribers. I really want to be able to show everyone BUT subscribers.
I’m also getting this error:
Warning: trim() expects parameter 1 to be string, array given in /public_html/wp-includes/user.php on line 494
/**
* Front-end display of widget
**/
public function widget( $args, $instance ) {extract( $args );
$title = apply_filters('widget_title', $instance['title'] );
$items_num = $instance['items_num'];
$users = array_merge( get_users('role=administrator'), get_users('role=editor'), get_users('role=author'), get_users('role=contributor') ); // get all of the users except subscribers
$users_exclude = $instance['users_exclude']; // excludes specified user ID's separated by commasecho $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
$query_args = array(
'role' => $users,
'orderby' => 'post_count',
'number' => $items_num,
'exclude' => $users_exclude
);
$authors = get_users( $query_args );So what am I doing wrong? Is there a better way to do this?
Even better… It would be awesome to have a group of checkboxes for people to select which roles they want in the widget settings, but at the very least I just need to exclude subscribers.
- The topic ‘Specifying multiple user roles with PHP’ is closed to new replies.