In my WordPress v5.8.1, I have a list of authors who post in custom posts song and poem. With the below code I am getting the list of authors who posted in the both or either in one custom post.
$authors = get_users(array(
'who' => 'authors',
'has_published_posts' => array('song','poem'),
'orderby' => 'post_count',
'order' => 'DESC',
'number' => '15'
));
Below code is listing all the authors with their post counts:
foreach ($authors as $user) {
$name = $user->first_name . ' ' . $user->last_name;
$songs = count_user_posts($user->ID, $post_type = "song");
$poems = count_user_posts($user->ID, $post_type = "poem");
echo $name.' has '. $songs .' songs, and '. $poems .' poems;
}
With 'orderby' => 'post_count' in the arguments, I expected the authors list with highest combined custom posts count displayed first, however it is showing randomly with no order, neither by post_counts nor ID.
How can I order the authors with most combined total posts?