Title: count_user_posts on multisite network
Last modified: August 31, 2016

---

# count_user_posts on multisite network

 *  Resolved [emiliengerbois](https://wordpress.org/support/users/emiliengerbois/)
 * (@emiliengerbois)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/count_user_posts-on-multisite-network/)
 * Hi,
    I’m trying to use count_user_posts to get the number of posts a user has
   edited on different subsites and in different post types. That’s why I use switch_to_blog.
   I then want to display this count through a shortcode on the user’s profile, 
   which is managed by ultimate member.
 * My problem is the following code works only if the post type is page or post,
   but I need it to work with CPTs (woocommerce products on site 4 and activities
   on site 1).
 * I hope you’ll be able to help me because I can’t get what’s wrong … Thank you
   so much in advance, here’s the code :
 *     ```
       function afficher_nb_posts_user() {
   
       	global $ultimatemember;
       	$quest_user = um_profile_id();
   
           		switch_to_blog(4);
       		$myquest_post_count = count_user_posts( $quest_user , 'product' );
           		restore_current_blog();
   
           		switch_to_blog(1);
       		$quest_post_count = count_user_posts( $quest_user , 'page' );
           		restore_current_blog();
   
       	$total_posts = ($myquest_post_count + $quest_post_count);
       	return $total_posts;
       }
       add_shortcode( 'nb_posts_user', 'afficher_nb_posts_user' );
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [emiliengerbois](https://wordpress.org/support/users/emiliengerbois/)
 * (@emiliengerbois)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/count_user_posts-on-multisite-network/#post-7164117)
 * Hi again, I solved it changing the way I get the data, finally using $wpdb and
   WHERE, and [thanks to this post also](http://wordpress.stackexchange.com/questions/212321/multisite-posts-in-categories-on-network/212330#212330).
 * Hope this helps someone 😉

Viewing 1 replies (of 1 total)

The topic ‘count_user_posts on multisite network’ is closed to new replies.

## Tags

 * [multisite](https://wordpress.org/support/topic-tag/multisite/)
 * [shortcake](https://wordpress.org/support/topic-tag/shortcake/)
 * [switch_to_blog](https://wordpress.org/support/topic-tag/switch_to_blog/)

 * In: [Networking WordPress](https://wordpress.org/support/forum/multisite/)
 * 1 reply
 * 1 participant
 * Last reply from: [emiliengerbois](https://wordpress.org/support/users/emiliengerbois/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/count_user_posts-on-multisite-network/#post-7164117)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
