wp_list_authors

List all the authors of the site, with several options available.

Description

(string|void) wp_list_authors( (string) $args = '' ); 

Returns (string|void)

The output, if echo is set to false.

Parameters (1)

0. $args — Optional. (string) => ''
Array or string of default arguments.

Options

  • orderby (string) => 'name'

    How to sort the authors. Accepts nicename,, email., url, registered, user_nicename, user_email, user_url, user_registered, name, display_name, post_count, ID, meta_value, user_login.

  • order (string) => 'ASC'

    Sorting direction for $orderby. Accepts ASC,, DESC..

  • number (int) => (all authors)

    Maximum authors to return or display.

  • optioncount (bool) => false

    Show the count in parenthesis next to the author's name.

  • exclude_admin (bool) => false

    Whether to exclude the admin account, if it exists.

  • show_fullname (bool) => false

    Whether to show the author's full name.

  • hide_empty (bool) => true

    Whether to hide any authors with no posts.

  • feed (string) => ''

    If not empty, show a link to the author's feed and use this text as the alt parameter of the link.

  • feed_image (string) => ''

    If not empty, show a link to the author's feed and use this image URL as clickable anchor.

  • feed_type (string) => to default feed type

    The feed type to link to, such as rss2..

  • echo (bool) => true

    Whether to output the result or instead return it.

  • style (string) => ''

    If list,, each author is wrapped in an

  • element, otherwise the authors will be separated by commas.

  • html (bool) => true

    Whether to list the items in HTML form or plaintext.

  • exclude (array|string) => ''

    Array or comma/space-separated list of author IDs to exclude.

  • array(
    
        /**
         * How to sort the authors. Accepts 'nicename', 'email', 'url', 'registered',
         * 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name',
         * 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'.
         *
         * @type string
         * @default 'name'
         */
        'orderby' => 'name',
    
        /**
         * Sorting direction for $orderby. Accepts 'ASC', 'DESC'.
         *
         * @type string
         * @default 'ASC'
         */
        'order' => 'ASC',
    
        /**
         * Maximum authors to return or display.
         *
         * @type int
         * @default (all authors)
         */
        'number' => (all authors),
    
        /**
         * Show the count in parenthesis next to the author's name.
         *
         * @type bool
         * @default false
         */
        'optioncount' => false,
    
        /**
         * Whether to exclude the 'admin' account, if it exists.
         *
         * @type bool
         * @default false
         */
        'exclude_admin' => false,
    
        /**
         * Whether to show the author's full name.
         *
         * @type bool
         * @default false
         */
        'show_fullname' => false,
    
        /**
         * Whether to hide any authors with no posts.
         *
         * @type bool
         * @default true
         */
        'hide_empty' => true,
    
        /**
         * If not empty, show a link to the author's feed and use this text as the alt parameter of the link.
         *
         * @type string
         * @default ''
         */
        'feed' => '',
    
        /**
         * If not empty, show a link to the author's feed and use this image URL as clickable anchor.
         *
         * @type string
         * @default ''
         */
        'feed_image' => '',
    
        /**
         * The feed type to link to, such as 'rss2'.
         *
         * @type string
         * @default to default feed type
         */
        'feed_type' => to default feed type,
    
        /**
         * Whether to output the result or instead return it.
         *
         * @type bool
         * @default true
         */
        'echo' => true,
    
        /**
         * If 'list', each author is wrapped in an `` element, otherwise the authors will be separated by
         * commas.
         *
         * @type string
         * @default ''
         */
        'style' => '',
    
        /**
         * Whether to list the items in HTML form or plaintext.
         *
         * @type bool
         * @default true
         */
        'html' => true,
    
        /**
         * Array or comma/space-separated list of author IDs to exclude.
         *
         * @type array|string
         * @default ''
         */
        'exclude' => ''
    );        


    Usage

    1. if ( !function_exists( 'wp_list_authors' ) ) { 
    2. require_once ABSPATH . WPINC . '/author-template.php'; 
    3.  
    4. // Optional. Array or string of default arguments. 
    5. $args = array( 
    6. 'orderby' => 'name', 
    7. 'order' => 'ASC', 
    8. 'number' => (all authors), 
    9. 'optioncount' => false, 
    10. 'exclude_admin' => false, 
    11. 'show_fullname' => false, 
    12. 'hide_empty' => true, 
    13. 'feed' => '', 
    14. 'feed_image' => '', 
    15. 'feed_type' => to default feed type, 
    16. 'echo' => true, 
    17. 'style' => '', 
    18. 'html' => true, 
    19. 'exclude' => '' 
    20. ); 
    21.  
    22. // NOTICE! Understand what this does before running. 
    23. $result = wp_list_authors($args); 
    24.  

    Defined (1)

    The function is defined in the following location(s).

    /wp-includes/author-template.php  
    1. function wp_list_authors( $args = '' ) { 
    2. global $wpdb; 
    3.  
    4. $defaults = array( 
    5. 'orderby' => 'name', 'order' => 'ASC', 'number' => '',  
    6. 'optioncount' => false, 'exclude_admin' => true,  
    7. 'show_fullname' => false, 'hide_empty' => true,  
    8. 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,  
    9. 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => '' 
    10. ); 
    11.  
    12. $args = wp_parse_args( $args, $defaults ); 
    13.  
    14. $return = ''; 
    15.  
    16. $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); 
    17. $query_args['fields'] = 'ids'; 
    18. $authors = get_users( $query_args ); 
    19.  
    20. $author_count = array(); 
    21. foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" ) as $row ) { 
    22. $author_count[$row->post_author] = $row->count; 
    23. foreach ( $authors as $author_id ) { 
    24. $author = get_userdata( $author_id ); 
    25.  
    26. if ( $args['exclude_admin'] && 'admin' == $author->display_name ) { 
    27. continue; 
    28.  
    29. $posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0; 
    30.  
    31. if ( ! $posts && $args['hide_empty'] ) { 
    32. continue; 
    33.  
    34. if ( $args['show_fullname'] && $author->first_name && $author->last_name ) { 
    35. $name = "$author->first_name $author->last_name"; 
    36. } else { 
    37. $name = $author->display_name; 
    38.  
    39. if ( ! $args['html'] ) { 
    40. $return .= $name . ', '; 
    41.  
    42. continue; // No need to go further to process HTML. 
    43.  
    44. if ( 'list' == $args['style'] ) { 
    45. $return .= '<li>'; 
    46.  
    47. $link = sprintf( '<a href="%1$s" title="%2$s">%3$s</a>',  
    48. get_author_posts_url( $author->ID, $author->user_nicename ),  
    49. /** translators: %s: author's display name */ 
    50. esc_attr( sprintf( __( 'Posts by %s' ), $author->display_name ) ),  
    51. $name 
    52. ); 
    53.  
    54. if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) { 
    55. $link .= ' '; 
    56. if ( empty( $args['feed_image'] ) ) { 
    57. $link .= '('; 
    58.  
    59. $link .= '<a href="' . get_author_feed_link( $author->ID, $args['feed_type'] ) . '"'; 
    60.  
    61. $alt = ''; 
    62. if ( ! empty( $args['feed'] ) ) { 
    63. $alt = ' alt="' . esc_attr( $args['feed'] ) . '"'; 
    64. $name = $args['feed']; 
    65.  
    66. $link .= '>'; 
    67.  
    68. if ( ! empty( $args['feed_image'] ) ) { 
    69. $link .= '<img src="' . esc_url( $args['feed_image'] ) . '" style="border: none;"' . $alt . ' />'; 
    70. } else { 
    71. $link .= $name; 
    72.  
    73. $link .= '</a>'; 
    74.  
    75. if ( empty( $args['feed_image'] ) ) { 
    76. $link .= ')'; 
    77.  
    78. if ( $args['optioncount'] ) { 
    79. $link .= ' ('. $posts . ')'; 
    80.  
    81. $return .= $link; 
    82. $return .= ( 'list' == $args['style'] ) ? '</li>' : ', '; 
    83.  
    84. $return = rtrim( $return, ', ' ); 
    85.  
    86. if ( ! $args['echo'] ) { 
    87. return $return; 
    88. echo $return;