Popular Authors ships four PHP functions you can call from a theme, child theme, or plugin to display or fetch author data. All functions live in the global namespace and require Top 10 to be active.

Render or return the popular authors list.

<?php wzpa_list_popular_authors( array(
    'number'        => 10,
    'optioncount'   => true,
    'show_avatar'   => true,
    'show_fullname' => false,
    'echo'          => true,
) ); ?>

Parameters: $args (array, optional) — accepts the full set of arguments listed under Display arguments below. The default echo argument is true, which prints the output. Pass 'echo' => false to receive the HTML as a string.

Returns: void|string — void when echo is true, the HTML string when echo is false.

Fetch the raw list of popular author IDs and visit counts without rendering any markup.

<?php
$authors = wzpa_get_popular_author_ids( array(
    'number' => 5,
    'daily'  => true,
) );

foreach ( $authors as $author ) {
    echo absint( $author->author_id ) . ': ' . absint( $author->visits ) . "n";
}
?>

Parameters: $args (array, optional) — see Query arguments below.

Returns: object — array of rows with author_id and visits properties.

wzpa_display_top_posts_by_author()

Render or return the most popular posts for a specific author. Backed by Top 10‘s tptn_pop_posts().

<?php
echo wzpa_display_top_posts_by_author(
    42,             // Author ID.
    'id',           // Field: id | slug | email | login.
    array(
        'posts_per_page' => 5,
    ),
    true            // Echo? Pass false to return the HTML string.
);
?>

Parameters:

  • $author (int|string, required) — value to look up the author by. With $field = 'id', pass a numeric user ID.
  • $field (string, optional) — field to look up the author by. Accepts id, slug, email, or login. Default id.
  • $args (array, optional) — display arguments passed to tptn_pop_posts().
  • $echo_value (bool, optional) — whether to print the output. Default true.

Returns: string|void — HTML string when $echo_value is false, void otherwise.

Return the merged defaults for the popular authors display. Useful when you want to read the configured defaults without re-implementing the merge logic yourself.

<?php
$defaults = wzpa_list_popular_authors_args();
?>

Parameters: $args (array, optional) — overrides applied on top of the defaults.

Returns: array — full list of display arguments with undefined values filled in.

Display arguments

These arguments are accepted by wzpa_list_popular_authors()Opens in a new window and wzpa_list_popular_authors_args(). The same key set is exposed by the shortcode and the block.

KeyTypeDescription
numberIntegerMaximum authors to return. Default -1 (all).
dailyBooleanUse daily counts instead of overall counts. Default false.
daily_rangeInteger / NullDays in the custom period. Default null.
hour_rangeInteger / NullHours in the custom period. Default null.
offsetIntegerAuthors to skip from the top of the list. Default 0.
optioncountBooleanShow the visit count. Default true.
show_postcountBooleanShow the published post count. Default false.
exclude_adminBooleanSkip the admin user. Default false.
show_fullnameBooleanUse first and last name. Default false.
show_avatarBooleanDisplay the avatar. Default false.
hide_emptyBooleanHide authors with no posts. Default true.
cacheBooleanCache the HTML output. Default true.
echoBooleanPrint the result instead of returning it. Default true.
includeArray / StringAuthor IDs to include. Overrides exclude. Default empty.
excludeArray / StringAuthor IDs to exclude. Default empty.
post_typeStringComma-separated list of post types. Default post.
stylesStringStyle key: no_style, card, or left_thumbs. Default empty.
before_listStringHTML before the list. Default <ul>.
after_listStringHTML after the list. Default </ul>.
before_list_itemStringHTML before each list item. Default <li>.
after_list_itemStringHTML after each list item. Default </li>.

Query arguments

These arguments are accepted by wzpa_get_popular_author_ids()Opens in a new window and map directly to the database query that aggregates visits from Top 10’s tables.

KeyTypeDescription
blog_idIntegerSite ID. Default is the current site.
numberIntegerAuthors to limit the query to. -1 returns all. Default -1.
dailyBooleanQuery daily totals instead of overall totals. Default false.
daily_rangeIntegerDays in the custom period. Default empty.
hour_rangeIntegerHours in the custom period. Default empty.
offsetIntegerAuthors to offset. Default 0.
pagedIntegerPage of results to return. Default 1.
includeArray / StringAuthor IDs to include. Default empty array.
excludeArray / StringAuthor IDs to exclude. Default empty array.

See also

Was this article helpful?