I cannot use the 'orderby' => 'post_count' as contributors have multiple posts assigned to them.
Rather, for each user output, I get their $post_count using the count_user_posts() function.
How can I re-order the items based on this number? Highest to lowest?
The user post count is not part of the $users array :(
// order contributors
$args = array(
'role' => contributors,
'orderby' => 'post_count',
'order' => 'ASC',
'fields' => 'all'
);
// The Query
$user_query = new WP_User_Query( $args );
$users = $user_query->get_results();
echo '<ul>';
$i = 0;
foreach ( $users as $user ) {
$post_count = count_user_posts( $user->id );
if ( count_user_posts( $user->id ) >= 1 ) {
echo '<li class="ws-sort" data-sort="' . $post_count . '"><a href="' . site_url() . '/author/' . $user->user_nicename . '">' . $user->display_name . '</li>';
if (++$i == 8) break;
}
}
echo '</ul>';