Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I exclude authors by ID from this:

<?php
//displays all users with their avatar and their posts (titles)
$blogusers = get_users_of_blog();
if ($blogusers) {
  foreach ($blogusers as $bloguser) {
    echo '<div class="content-slider-body">';
    $user = get_userdata($bloguser->user_id);
    echo '<div class="grid col-140">' . get_avatar( $user->ID, 128 ) . '</div>';
    $args=array(
      'author' => $user->ID,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      //echo 'List of Posts for ' . user->user_firstname . ' ' . $user->user_lastname;
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Where $that_user_your_filtering_out is the user/author ID you wan't to filter out, make this modification to your loop

foreach ($blogusers as $bloguser) {
    // modification starts here
    if($bloguser->user_id == $that_user_your_filtering_out){
        continue;
    }
    // modification ends here
    echo '<div class="content-slider-body">';
    $user = get_userdata($bloguser->user_id);
share|improve this answer
    
Perfect, thank you!! –  Phantasmix Oct 3 '12 at 20:08
    
Tom, can this be modified for multiple user IDs? I tried array(1,2) but that didn't work. –  Phantasmix Oct 3 '12 at 20:09
    
well the question "Is 1 the same as 1,2,3,4,5,6 " explains why it doesn't work. Instead use the in_array function uk.php.net/manual/en/function.in-array.php –  Tom J Nowell Oct 3 '12 at 20:22
    
Thanks for pointing me in the right direction. This works to exclude multiple users: // modification starts here $excluded_users = array(1,3); // User Ids to exclude if (in_array($bloguser->user_id, $excluded_users)){ continue; } // modification ends here –  Phantasmix Oct 3 '12 at 21:56
    
=] Glad you got it working –  Tom J Nowell Oct 3 '12 at 22:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.