how to calculate the number of posts in a category and by author

Solution:1

You can use the get_usernumposts filter hook. try the below code. code will go in your active theme functions.php file.

function count_author_post_by_category( $count, $userid, $post_type, $public_only ){

    $author_posts = new WP_Query(array(
        'author'         => $userid,
        'posts_per_page' => -1,
        'tax_query'      => array(
            array(
                'taxonomy' => 'category',
                'field'    => 'slug',
                'terms'    => 'neuws', // your category slug.
            )
        )
    ));

    if( $author_posts->have_posts() ) {
        $count = $author_posts->found_posts;
    }

    return $count;

}
add_filter( 'get_usernumposts', 'count_author_post_by_category', 10, 4 );

Solution:2

You could do this by creating a custom WP_Query and then counting it. Note: You can replace the static ID of the user with your $userid variable.

$args = array( 
   'author' => 1,
   'cat'    => 5,
);

$my_query = new WP_Query( $args );
$my_count = $my_query->post_count;

Alternatively, you can use the category slug or author’s nice name (NOT name!) as well:

$args = array(
   'author_name'   => 'bob',
   'category_name' => 'editorial',
};