Skip to content

Commit

Permalink
Merge pull request #496 from justnorris/allow-hide-empty
Browse files Browse the repository at this point in the history
Allow `coauthors_wp_list_authors` to only query authors with posts
  • Loading branch information
rebeccahum committed Nov 6, 2018
2 parents 3130897 + 8a1e1ff commit f2905d3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions template-tags.php
Expand Up @@ -525,6 +525,7 @@ function the_coauthor_meta( $field, $user_id = 0 ) {
* feed (string) (''): If isn't empty, show links to author's feeds.
* feed_image (string) (''): If isn't empty, use this image to link to feeds.
* echo (boolean) (true): Set to false to return the output, instead of echoing.
* authors_with_posts_only (boolean) (false): If true, don't query for authors with no posts.
* @param array $args The argument array.
* @return null|string The output, if echo is set to false.
*/
Expand All @@ -542,16 +543,21 @@ function coauthors_wp_list_authors( $args = array() ) {
'style' => 'list',
'html' => true,
'number' => 20, // A sane limit to start to avoid breaking all the things
'guest_authors_only' => false
'guest_authors_only' => false,
'authors_with_posts_only' => false,
);

$args = wp_parse_args( $args, $defaults );
$return = '';

$term_args = array(
'orderby' => 'name',
'hide_empty' => 0,
'number' => (int) $args['number'],
/*
* Historically, this was set to always be `0` ignoring `$args['hide_empty']` value
* To avoid any backwards incompatibility, inventing `authors_with_posts_only` that defaults to false
*/
'hide_empty' => (boolean) $args['authors_with_posts_only'],
);
$author_terms = get_terms( $coauthors_plus->coauthor_taxonomy, $term_args );

Expand Down

0 comments on commit f2905d3

Please sign in to comment.