Hi,
you need a child theme and a small code modification.
The code is explained here.
if ( bp_has_members( bp_ajax_querystring( 'members' ) ) )
is to replace by something like (can be different)
if ( bp_has_members( 'type=random' ) )
In a “buddypress” folder of your child theme, you add a copy of this file:
wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/members-loop.php
What ever you modify in that file while now be interpreted by BuddyPress. The advantage of this method is that BP can be updated while your modification in the child will always be save and taken in account over the current version.
You can also search the forum for members-loop to get other information.
@danbp Is it possible to this in bp-custom.php
I found this handy
It works in BP-custom.php — im trying to get it to load instead of “alphabetical”
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
class BP_Loop_Filters {
/**
* Constructor
*/
public function __construct() {
$this->setup_actions();
}
/**
* Actions
*
* @uses bp_is_active()
* @uses is_multisite()
*/
private function setup_actions() {
/**
* Adds the random order to the select boxes of the Members, Groups and Blogs directory pages
*/
// Members component is core, so it will be available
add_action( 'bp_members_directory_order_options', array( $this, 'random_order' ) );
// You need to check Groups component is available
if( bp_is_active( 'groups' ) )
add_action( 'bp_groups_directory_order_options', array( $this, 'random_order' ) );
// You need to check WordPress config and that Blogs Component is available
if( is_multisite() && bp_is_active( 'blogs' ) )
add_action( 'bp_blogs_directory_order_options', array( $this, 'random_order' ) );
}
/**
* Displays a new option in the Members/Groups & Blogs directories
*
* <a class="bp-suggestions-mention" href="https://buddypress.org/members/return/" rel="nofollow">@return</a> string html output
*/
public function random_order() {
?>
<option value="random"><?php _e( 'Random', 'buddypress' ); ?></option>
<?php
}
}
// 1, 2, 3 go !
function bp_loop_filters() {
return new BP_Loop_Filters();
}
add_action( 'bp_include', 'bp_loop_filters' );
You can use the ‘bp_after_has_members_parse_args’ hook to filter for random users adding it to the bp-cuscom.php file.
function random_users( $args ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return $args;
}
$args['type'] = 'random';
return (array) $args;
}
add_filter( 'bp_after_has_members_parse_args', 'random_users', 10 );
@espellcaste @danbp
That worked well!!! *thank you – thank you*
I also added the code below to display 50 users – is there a way to combine them or factor it down?
function more_users( $args ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return $args;
}
$args['per_page'] = '50';
return (array) $args;
}
add_filter( 'bp_after_has_members_parse_args', 'more_users', 10 );
?>
You can add as much options as you want:
function more_users( $args ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return $args;
}
$args['per_page'] = '50';
$args['type'] = 'random';
return (array) $args;
}
add_filter( 'bp_after_has_members_parse_args', 'more_users', 10 );