In order to use wp_count_posts()
as you would on a single site, pass the blog id into the switch_to_blog()
function before calling wp_count_posts()
.
Example:
function wpse_get_post_count( $blog_id ){
switch_to_blog( $blog_id );
$post_count = wp_count_posts();
restore_current_blog();
return $post_count;
}
Ensure restore_current_blog()
is used after every switch_to_blog()
or you will risk difficulties mentioned in the notes section of the documentation and this WordPress Stack Exchange answer.