BuddyDev

Search

[Resolved] Member Types Pro Director Tab Sorting

  • Participant
    Level: Initiated
    Posts: 1
    Colin Lau on #15468

    Is it possible to have the member type tabs in the members directory sorted alphabetically?

    thank you in advance

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #15471

    Hi Colin Lau,
    Thank you for asking.

    The plugin does not provide it out of the box and the order is controlled by BuddyPress.

    It i still possible to reorder the list. You can use the following functions.

    
    
    /**
     * Comparator function.
     *
     * @param Object $mtype_1 member type 1.
     * @param Object $mtype_2 member type 2.
     *
     * @return int
     */
    function buddydev_member_type_comparator( $mtype_1, $mtype_2 ) {
    	// compare by member type unique name(key).
    	return strcmp( $mtype_1->name, $mtype_2->name );
    
    	// compare by labels instead. to use it, comment the previous line using // and uncomment the line below.
    	// return strcmp( $mtype_1->labels['singular_name'], $mtype_2->labels['singular_name'] );
    }
    
    /**
     * Filter Member Types and sort.
     *
     * @param array $member_types member type names or objects array.
     *
     * @return mixed
     */
    function buddydev_reorder_member_types( $member_types ) {
    
    	if ( empty( $member_types ) ) {
    		return $member_types;
    	}
    
    	// sort it.
    	uasort( $member_types, 'buddydev_member_type_comparator' );
    
    	return $member_types;
    }
    
    add_filter( 'bp_get_member_types', 'buddydev_reorder_member_types' );
    

    In the above example, I am ordering alphabetically by key.

    In order to order by label, you can uncomment and comment the line as mentioned in the comparator function.

    Hope this helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 1
    Colin Lau on #15472

    Works great, thank you so much!

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #15473

    You are welcome 🙂

The topic ‘ [Resolved] Member Types Pro Director Tab Sorting’ is closed to new replies.

This topic is: resolved