Sorting output of coauthors_wp_list_authors function – Co-Authors Plus plugin WordPress

The Co-Authors Plus plugin has a function called coauthors_wp_list_authors() that spits out a list of all the co-authors being used on the site. It accepts many of the same arguments as the standard wordpress function, wp_list_authors().

Except it doesn’t accept “order” or “orderby”. (here’s a list of what it accepts). So without those arguments, how can I customize the sort order of the authors?

Read More

My usage is an “authors” page that lists every co-author on the site. The default sort seems to be the date that the co-author was created.

My function looks like this:

function display_authors() {
  $author_list = coauthors_wp_list_authors('number=500&echo=0');
  ?>
    <div class="author_list"><ul><?php return $author_list ?></ul></div>
  <?php
}

Thank you!

Related posts

Leave a Reply

1 comment

  1. Funny. I am looking to do the same thing. I submitted a pull request to the repo for the ability to filter the author array returned from get_terms. If this gets pulled, it’d be as simple as adding a filter on coauthors_wp_list_authors_array and filtering that array into the order that you want it. Until then…

    — UPDATE! (cue the Unsolved Mysteries update music) —

    OK so it looks like the pull request was merged and it was deployed to Automattic’s public SVN repo for VIP plugins but they haven’t updated the .org plugin, so feel free to pester them to update it 🙂

    For prudence sake I will duplicate my response to your wordpress.org forum thread on how to use this filter to, for example, sort by display_name:

    ok so, this is untested but should work. it also may not be the most efficient way of doing things.

    This sorts by display_name if you want to sort by another property, change display_name to the property in the line

    $sorted[$item->display_name][] = $item;
    

    Note that both objects (the ‘mock’ user object and the WP_User object) must have the same properties for this to work, also note how the WP_User object uses the magic method __get().

    function coauthor_sort( $authors ) {
    
        $sorted = array();
    
        foreach ($authors as $item) {
            $sorted[$item->display_name][] = $item;
        }
    
        uksort($sorted, "strnatcasecmp");
        $sorted_authors = array();
    
        foreach ($sorted as $subArray) {
            foreach ($subArray as $item)  {
                $sorted_authors[] = $item;
            }
        }
    
        return $sorted_authors;
    
    }
    add_filter('coauthors_wp_list_authors_array','coauthor_sort');