wordpress php: replace get_users_of_blog()

Posted on 2012-08-10
Last Modified: 2012-08-29

I have the code below that someone here at EE helped me put together.  It pulls up  a list of authors that have posted articles within the last 20 days, and displays the name of each author and their last three articles (plus an email link and link to their author page).

I was looking for a way to limit this to a specific user role. While looking up get_users_of_blog()  I found that this function is depreciated.  I also found that the get_users() replacement has a parameter for limiting it to a specific user role - just what I needed :)

However, I find that if I replace the get_users_of_blog()  with get_users() - things stop working in the script. I just get the three articles from the first author listed over and over again, and no author names, email and author page links.

So, apparently, I can't simply replace get_users_of_blog()  with  get_users()   they must provide different results.

What do I need to do to fix this?

Thanks for any help!    Chris

ps: currently using wordpress  3.2.1


function filter_where( $where = '' ) {
      // posts in the last 20 days
      $where .= " AND post_date > '" . date('Y-m-d', strtotime('-20 days')) . "'";
      return $where;
$skip_users = array(1,3);  //skip user ID 1 and 3
$blogusers = get_users_of_blog();
if ($blogusers) {//var_dump($blogusers);
  foreach ($blogusers as $bloguser) {
    if (!in_array($bloguser->user_id, $skip_users) ) {
      $user = get_userdata($bloguser->user_id);
        'author' => $user->ID,
        'post_type' => 'post',
        'post_status' => 'publish',
        'posts_per_page' => 3,
        'caller_get_posts'=> 1
      $my_query = null;

      add_filter( 'posts_where', 'filter_where' );
      $my_query = new WP_Query($args);
      remove_filter( 'posts_where', 'filter_where' );
      if( $my_query->have_posts() ) {
       echo '<strong class="staff">

<a href="'.strtolower($user->user_firstname . '-' . $user->user_lastname) . '"'.$user->user_firstname . ' ' . $user->user_lastname .'">'. $user->user_firstname . ' ' . $user->user_lastname . '</a>
</strong><br />';
echo '<ul class="posts blog black_wrapper" style="padding-top:13px;margin-bottom:0px;">';
        while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <li style="margin-left:-10px;margin-bottom:2px;font-weight:bold;font-size:12px;"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
 echo '</ul>';
echo '<span class="staff_more"><span style="padding-right:20px;padding-bottom:-2px"><a href="mailto:' . $user->user_firstname . '_' . $user->user_lastname . '" title="Email '.$user->user_firstname . ' ' . $user->user_lastname .'"><img src=""></a></span> <a href="'.strtolower($user->user_firstname . '-' . $user->user_lastname) . '" title="Read More From '.$user->user_firstname . ' ' . $user->user_lastname .'">More From '. $user->user_firstname . ' ' . $user->user_lastname . '</a></span><br />';
//echo the_author_posts_link();

  wp_reset_query();  // Restore global post data stomped by the_post().
Question by:St_Aug_Beach_Bum
    LVL 14

    Accepted Solution

    Try adding this:

    $thisuser = $bloguser->user_id;
    echo $thisuser->roles[0];

    In this if statement:

    if (!in_array($bloguser->user_id, $skip_users) ) {

    If it echos out the correct role for each user, then you could just add an additional if statement allowing the rest of the code to run if the role equals the one you want to allow to show.

    If you need a list of the roles to compare to, you can find them here:

    Author Closing Comment

    So very sorry for the delay in getting back to you, got working on other things and finally rounded back 'round to this :)  Works great!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
    The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Go t…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now