I am using the function below to count posts for users (including custom post types). I am putting together a list of users and want to order them by this count function. The orderby options for the get_users() function are limited, and post_count doesn't include custom post types. How can I order my users using this function?
Function:
function foo_count_posts( $userid, $post_type = '', $post_status = 'publish') {
global $wpdb;
$query = "SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = $userid AND (post_type = 'post' OR post_type='foo') AND post_status = '$post_status'";
$counter = $wpdb->get_var($query);
return apply_filters( 'get_usernumposts', $counter, $userid );
}
Then I call the function to get the count:
echo foo_count_posts($user_id);