Yes, the get_users_of_blog()
function is deprecated, and the reason your code breaks after using get_users()
is the ->user_id
part, you should use ->ID
instead.
$blogusers = get_users();
if ($blogusers) {
foreach ($blogusers as $bloguser) {
$args = array(
'author' => $bloguser->ID,
'showposts' => 1,
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
...........
<?php endwhile;
}
}
}
If you are on a multisite, you should set the blog_id
argument of get_users
to your blog’s ID.
Now, about excluding the authors. If you take a look at the author parameters of WP_Query()
, there’s a author__not_in
argument that accepts an array of author IDs. So, to exclude the test
role from your query, set the role__in
or role
argument of get_users()
to test
, and then use the results in your WP_Query()
. You didn’t provide accurate details so I’m not sure what exactly you are looking after, but these should do the trick.