We help IT Professionals succeed at work.
Get Started

wordpress php: replace get_users_of_blog()

Chris Andrews
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="http://www.mysite.com/journalist/'.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 . '@mysite.com" title="Email '.$user->user_firstname . ' ' . $user->user_lastname .'"><img src="http://www.mysite.com/email.gif"></a></span> <a href="http://www.mysite.com/journalist/'.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().
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE