I assume the above function works well for you to get the count for the posts including the custom post types
and you just need help in ordering the users using this count.
I assume you already have the list of user ids lets say the array $userids
Lets use asort and arsort to do so
Put the above code in the active theme’s functions.php
file and use the below in the file where you need to get the ordering
$arr = array();
foreach( $userids as $userid ) {
$arr[$userid] = foo_count_posts($userid);
}
Now $arr
is the array with userid as key and post count as the value
To get the ascending order use
asort($arr);
var_dump($arr);
To get the descending order use
arsort($arr);
var_dump($arr);