BuddyPress: Members per Page in the Directory
Changes how many members the BuddyPress members directory shows per page, and can switch the default order to alphabetical.
Opens WPIDE on
Code
if ( ! function_exists( 'buddypress' ) ) {
return;
}
$wpide_bp_members_per_page = 48;
// "alphabetical", "newest", "active" or "" for the default.
$wpide_bp_default_order = 'alphabetical';
add_filter( 'bp_after_has_members_parse_args', function ( $args ) use ( $wpide_bp_members_per_page, $wpide_bp_default_order ) {
if ( ! bp_is_members_directory() && ! wp_doing_ajax() ) {
return $args;
}
$args['per_page'] = $wpide_bp_members_per_page;
// Only change the order when the visitor has not picked one.
if ( $wpide_bp_default_order && empty( $_REQUEST['type'] ) && empty( $_REQUEST['filter'] ) ) {
$args['type'] = $wpide_bp_default_order;
}
return $args;
} );
Notes
Set $wpide_bp_default_order to "" to keep BuddyPress's own "last active" order.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.