Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_get_member_type not returning value: ‘Invalid Taxonomy’


  • David Bisset
    Participant

    @dimensionmedia

    I’m going to break this down as simple as possible, because it’s a little nuts. Using the latest versions of WordPress and BuddyPress, no other plugins unless otherwise mentioned. Default WP theme.

    1. Go ahead and register a BuddyPress member type in bp-custom.php like so:
    https://gist.github.com/dimensionmedia/c49347c8e24f00f43450b37506b4e009

    2. Go into your WordPress backend -> users -> extended tab. Assign a user to that member type.

    3. Now place this code at the end of functions.php, using the $user_id of the user from #2:

    $user_id = 7;
    $member_type = bp_get_member_type( $user_id );
    echo $member_type; exit;

    Note this is crude but making it as simple as possible.

    Now you won’t get back anything, no matter what you assign the user to as far as user type. The bp_get_member_types() works though. When I attempt to trace through bp_get_member_type back to wp_get_object_terms I get a WP_ERROR of “Invalid Taxonomy”, apparently the $wp_taxonomies doesn’t contain “bp_member_type”.

    Please the same code in a front-end template like header.php and this works.

    So while i can use the function in templates, i can’t in my plugins (or functions.php).

    I’ve used bp_get_member_type() before – in a plugin – and didn’t run into problems. Trying to figure out what i’m missing. Probably something simple.

Viewing 3 replies - 1 through 3 (of 3 total)

  • Brajesh Singh
    Participant

    @sbrajesh

    Hi David,
    Most probably you are trying to access the member type directly in the functions.php. That is too early for it. A member type is only available on/after bp_init action. It is actually registered on bp_init priority 2.

    My suggestion will be to wrap the code that accesses the member type in a function and call it on bp_init or bp_template_redirect.

    Hope that helps.


    danbp
    Moderator

    @danbp

    Hi @dimensionmedia,

    have you tried with $member_types = bp_get_member_types( array(), 'objects' );

    I use this in a function like this:

    // Display tabs used to filter the members directory by types.

    
    function using_mt_display_directory_tabs() {
    	$member_types = bp_get_member_types( array(), 'objects' );
    
    	// Loop in member types to build the tabs
    	foreach ( $member_types as $member_type ) : ?>
    
    	<li id="members-<?php echo esc_attr( $member_type->name ) ;?>">
    		<a href="<?php bp_members_directory_permalink(); ?>"><?php printf( '%s <span>%d</span>', $member_type->labels['name'], using_mt_count_member_types( $member_type->name ) ); ?></a>
    	</li>
    
    	<?php endforeach;
    }
    add_action( 'bp_members_directory_member_types', 'using_mt_display_directory_tabs' );

    Here a complete working example.


    David Bisset
    Participant

    @dimensionmedia

    Thanks for the input @danbp and @sbradjesh.

    Dan – thanks for the suggestion, but I was able to get the types all along. 🙂
    Bradjesh – you’re right regarding the order but I thought i was able to do this before, especially working with plugins that I needed to work with the member type for some logic. I made adjustments based on your suggestion. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar