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)
Viewing 1 replies (of 1 total)
- The topic ‘count_user_posts on multisite network’ is closed to new replies.