How to Count Custom Post Types in Nav Tabs?
-
I added a Post Tab to my Buddypress Navigation Tab Menu which displays the latest Posts and Custom Posts for each user.
Now I want to add the total number of all Posts (standard wordpress posts and CPT posts) but only standard posts get counted. What am I doing wrong?
function bpck_post_profile_setup_nav() { global $bp; $parent_slug = 'post'; $child_slug = 'post_sub'; $post_count = count_user_posts( bp_displayed_user_id(), array('video','discography','post' ) ); bp_core_new_nav_item( array( 'name' => 'My Posts <span>'.$post_count.'</span>', 'slug' => $parent_slug, 'parent_url' => $bp->loggedin_user->domain . $parent_slug.'/', 'screen_function' => 'profile_page_show_screen', 'position' => 40, 'default_subnav_slug' => $child_slug ) ); } function profile_page_show_screen() { add_action( 'bp_template_content', 'profile_post_page_screen_content' ); bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) ); } function profile_post_page_screen_content() { do_action( my_profile_post); } add_action( 'bp_setup_nav', 'bpck_post_profile_setup_nav' );
What’s even more confusing if I add
function my_custom_userpostcount() { echo '<span>' . count_user_posts( bp_displayed_user_id(), array('video','discography','post' ) ) . ' Posts</span>'; } add_action( 'bp_before_member_header_meta', 'my_custom_userpostcount');
to the user header, the total count number is correct, it counts all post types in the array.
Don’t know what I’m doing wrong.
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- You must be logged in to reply to this topic.