Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active December 24, 2023 02:05
Show Gist options
  • Save KaineLabs/23b8874c138c2b08f3680c450c981328 to your computer and use it in GitHub Desktop.
Save KaineLabs/23b8874c138c2b08f3680c450c981328 to your computer and use it in GitHub Desktop.
BuddyPress Add Member Types as a Dropdown in Members Directory
<?php
/**
* Add Member Types as a Dropdown in Members Directory.
*/
function youzifyc_add_new_members_directory_filter() {
// Get Member Types
$member_types = bp_get_member_types( '', 'objects' );
if ( empty( $member_types ) ) {
return false;
}
?>
<li id="members-type" class="last">
<select id="members-type">
<option value=""><?php _e( 'Member Type', 'youzer' );?></option>
<?php foreach ( $member_types as $type ): ?>
<?php
if ( 0 == $type->has_directory ) {
continue;
}
// Get Type
$type_infos = bp_get_term_by( 'slug', $type->name, bp_get_member_type_tax_name() );
if ( ! isset ( $type_infos->count ) || $type_infos->count < 1 ) {
continue;
}
?>
<option value="<?php echo $type->name; ?>"><?php echo $type->labels['name']; ?></option>
<?php endforeach; ?>
</select>
</li>
<?php
}
add_action( 'bp_members_directory_member_sub_types', 'youzifyc_add_new_members_directory_filter' );
/**
* Script
*/
add_action( 'wp_footer' , 'yzc_add_script', 1 );
function yzc_add_script() { ?>
<style type="text/css">.yzmt-directory-tab { display: none !important; }</style>
<script type="text/javascript">
( function( $ ) {
'use strict';
jQuery( document ).ready( function() {
$('select#members-type').on('change', function() {
if ( this.value == '' ) {
$( '#members-all a' ).click();
} else {
$( '.youzify-directory-filter' ).find( 'a[href*="type/' + this.value +'"]').click();
}
});
});
})( jQuery );
</script>
<?php
}
@CordialGit
Copy link

I currently use plain BuddyPress. And when I installed this code, it broke my website.

That's when I got to see that this Code is purely for Youzify.

Now, you have extensive knowledge of BuddyPress.

Would you be able to recreate another version of this Code that will work in plain BuddyPress?

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment