phpwordpressbuddypress

Problem retrieving value of a function declared in wordpress


I want to display the member count according to the member type. i'm using buddypress member type pro version

I was trying to retrieve count value of buddypress member type . This feature is not available with buddypress member type pro so write a function that will allow to get the count if you give it member type name. But I'm stucked to retrieve the value. I wrote a short code for that but that also not working. i'm attaching the declared function details and short code. Please help me on this.

Code:

function buddydev_get_user_count_by_member_type( $member_type ) {
    $term = bp_get_term_by( 'slug', $member_type, bp_get_member_type_tax_name() );
    if ( $term ) {
        return $term->count;
        }
 
    return 0;
}

add_shortcode( 'mcount', ' buddydev_get_user_count_by_member_type' );

Solution

  • You have added space in the function name "buddydev_get_user_count_by_member_type" that's why it is not working just remove the space and it will work.

    function buddydev_get_user_count_by_member_type( $member_type ) {
        $term = bp_get_term_by( 'slug', $member_type, bp_get_member_type_tax_name() );
        if ( $term ) {
            return $term->count;
            }
     
        return 0;
    }
    
    add_shortcode( 'mcount', 'buddydev_get_user_count_by_member_type' );