1

I want to have the authors listed like usual from wp_list_authors() but I know there are a couple of ones I would like to exclude from the list as well. Is there a way to do that?

Thanks

2
  • @Paul Sheldrake: Do you always want to exclude those users, or only in certain contexts? If only in certain contexts, which ones? Oct 7, 2010 at 17:58
  • Typically I would always want to exclude them. Oct 11, 2010 at 20:59

4 Answers 4

3

wp_list_authors() now does have an exclude parameter. So you can exclude the authors you want by their user ID.

It accepts:

An array, comma-, or space-separated list of author IDs to include. Default empty.

Examples:

// exclude just the author with the ID 4
wp_list_authors([ 'exclude' => 4 ]);


// exclude the authors with the IDs 4 and 7
wp_list_authors([ 'exclude' => [ 4, 7 ] ]);

// or
wp_list_authors([ 'exclude' => '4, 7' ]);
3

It seems wp_list_authors does not have any filters, nor does get_users_of_blog, the function it uses to get the user list. So you either have to regex-and-replace the output yourself, or create a similar function with an extra parameter to specify authors to exclude. It's not too big, and most of the code is spent handling options, so it isn't that much duplication.

You could always vote for the existing Trac ticket to get an exclude parameter added in a future version!

3
  • @EAMann: Ah, you didn't have to delete your answer for this!
    – Jan Fabry
    Oct 7, 2010 at 15:30
  • We were saying the same thing. No reason to duplicate what was already a good answer.
    – EAMann
    Oct 7, 2010 at 15:50
  • @EAMann: But the rep man! Think of the rep! Oh, wait - a diamond next to your name. Nevermind. You're one of those.
    – Jan Fabry
    Oct 7, 2010 at 15:57
1

I have used the following code to include info from Authors (WordPress users) in a page template. It could be reversed to exclude authors.

<?php
            //display selected users
            $userids_to_display = array(4,221,22,3,5,9,235,236,250); // wordpress user IDs to include
            $blogusers = get_users_of_blog();
            if ($blogusers) {
              foreach ($blogusers as $bloguser) {
                if ( in_array($bloguser->user_id, $userids_to_display) ) {
                  $user = get_userdata($bloguser->user_id);
                  echo '<div>';
                  echo '<div class="alignleft">'.get_avatar($user->ID).'</div>';
                  echo '<div class="user-data"><h3>' . $user->user_firstname . ' ' . $user->user_lastname . '</h3>';
                  echo '<div class="author-description">'.$user->description.'</div>';                
                  echo '</div>';
                }
              }
            }
            ?>
0

Since it seems there is no way to do this without a custom function, you could use jQuery to find their names and hide them after the list is generated. Something like this:

$('ul.author_list li:contains("John")').remove();

I also found a plugin that can do this for you: List Authors Plus

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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