count_many_users_posts except current logged in user?

Is there a way to count and show the count of all author posts in a custom post type except the current logged in user?

I was hoping there’s a way to do it with count_many_users_posts but it doesn’t appear there is a way to exclude authors, only include them.

I’ve done multiple searches but have found nothing to even hint at a right direction to head in.

Here’s the codex example:

<?php
    $users = array(1, 3, 9, 10);
    $counts = count_many_users_posts($users);
    echo 'Posts made by user 3: ' . $counts[3];
?>

TIA!

ON EDIT:

Just wanted to let y’all know I haven’t revisited this yet. I will try the solutions and come back when I get there. Another project popped up for the moment.

Thanks!

Solutions Collecting From Web of "count_many_users_posts except current logged in user?"

Inclusion and exclusion are often reversible. “Not this” (exclusive) is equal to “All of that, skipping this” (inclusive).

If in general the function does precisely what you need, you could just make a full list of user IDs and throwing the current one out.

If the number of users on your site, is relatively small, you could try:

$user_ids = get_users( 
    [ 
        'fields'    => 'ID',                     // Only return the user IDs
        'exclude'   => (array) get_current_user_id(),    // Exclude the current user
        'number'    => 10                        // Modify this number to your needs
    ] 
);

and then use this as an input into the count_many_users_posts() function:

$counts = count_many_users_posts( 
    (array) $user_ids,
    $post_type   = 'post', 
    $public_only = false 
);

where you can adjust the post type to your needs.

There are a number of WordPress query functions you could utilize, but I recommend keeping the query lean and avoid using a WP_Query since you don’t need the post content. Here’s a little function that will return the number of posts of post_type that are not owned by user_id:

function get_post_count_exclude_user($post_type,$user_id) {
    $query = "SELECT COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s AND post_author <> %s";
    return $wpdb->get_var( $wpdb->prepare( $query, $post_type, $user_id ) );
}

$number_of_posts = get_post_count_exclude_user('my_post_type',get_current_user_id());

I don’t know why this works, but it does.

        $authorid = get_current_user_id();
        query_posts(array( 
            'post_type' => 'tasks',
            'author' => -$authorid,
        ) ); 
            $count = 0;
            while (have_posts()) : the_post(); 
                $count++; 
            endwhile;
            echo '<p class="else"><em>' .$count .'</em></p><span class="description">All other posts</span>';
        wp_reset_query();