最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - Filter to wp_list_authors

matteradmin6PV0评论

I am using wp_list_authors, to, how function name says, make a list of authors, but i want to show only "Authors". Now in my site, any account who publish a text ("Admin", "Editor") show his name in my list of authors, but i want ONLY users who are Authors. How can i make this happen?

My code now

<?php $args = array(
  'orderby'       => 'name',
  'order'         => 'ASC',
  'number'        => 6,
  'optioncount'   => true,
  'exclude_admin' => true,
  'show_fullname' => false,
  'hide_empty'    => true,
  'echo'          => true,
  'style'         => 'list',
  'html'          => true); ?>

I am using wp_list_authors, to, how function name says, make a list of authors, but i want to show only "Authors". Now in my site, any account who publish a text ("Admin", "Editor") show his name in my list of authors, but i want ONLY users who are Authors. How can i make this happen?

My code now

<?php $args = array(
  'orderby'       => 'name',
  'order'         => 'ASC',
  'number'        => 6,
  'optioncount'   => true,
  'exclude_admin' => true,
  'show_fullname' => false,
  'hide_empty'    => true,
  'echo'          => true,
  'style'         => 'list',
  'html'          => true); ?>
Share Improve this question asked Mar 25, 2019 at 17:33 Matheus RibeiroMatheus Ribeiro 11 bronze badge 1
  • At first glance it looks like your best bet is to fetch a list of all editors by role and then pass their IDs into your $args as 'exclude'. I don't think there's any way to hook 'role__not_in' => [ 'editor' ] into the get_users call it makes because the args get passed through wp_array_slice_assoc. So this isn't great: it might be worth making your own version of wp_list_authors you can customise, or caching some or all of this in transients if you call it a lot I suppose. – Rup Commented Mar 25, 2019 at 18:07
Add a comment  | 

1 Answer 1

Reset to default 1

wp_list_authors(), displays a list of the sites's authors (users), and if the user has authored any posts, the author name is displayed as a link to their posts.

Use

 $authors = get_users( [ 'role__in' => [ 'auther'] ],
                // add other parameters
                );

Then loop through $authors to create your own list.

foreach ( $authors as $author ) {
    // your list goes here
}

I hope this helps to start.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far