Link to home
Start Free TrialLog in
Avatar of Chris Andrews
Chris AndrewsFlag for United States of America

asked on

wordpress php: replace get_users_of_blog()

Hi,

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);
       $args=array(
        '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>
          <?php
        endwhile;
 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().
  }
}
ASKER CERTIFIED SOLUTION
Avatar of Heather Ritchey
Heather Ritchey
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Andrews

ASKER

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!