Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow coauthors_wp_list_authors to only query authors with posts #496

Merged
merged 4 commits into from Nov 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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