• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1007
  • Last Modified:

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().
  }
}
0
St_Aug_Beach_Bum
Asked:
St_Aug_Beach_Bum
1 Solution
 
DzynitCommented:
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: http://codex.wordpress.org/Roles_and_Capabilities
0
 
St_Aug_Beach_BumAuthor Commented:
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!
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now