BuddyDev

Search

Member directory sort by Random

  • Participant
    Level: Initiated
    Posts: 16
    Nushara on #34293

    Hey there,

    I was working on some different member sorting and stumbled upon a sort function for the directory. Problem is, it only supports ASC and DESC but no RAND() for example.

    Is there any way to change the function to also accept rand sorting? Or, is there any way to randomize the users before displaying them in the loop?

    What I’ve tried so far was:

    
    add_filter( 'bp_ajax_querystring', 'filter_ajax_querystring', 20, 2 );
    function filter_ajax_querystring( $querystring = '', $object = '' ) {
    	if( $object != 'members' ){return $querystring;}
    	$defaults = array(
    		'type'            => 'active',
    		'action'          => 'active',
    		'scope'           => 'all',
    		'page'            => 1,
    		'user_id'         => 0,
    		'search_terms'    => '',
    		'exclude'         => false,
    	);
    	$ch_querystring = wp_parse_args( $querystring, $defaults );
    	//Get Random users
    	if( $ch_querystring['type'] == 'random' ) {
    		$ch_querystring['type'] = 'all'; 
    		$ch_querystring['sort'] = 'RAND()';
    		return $ch_querystring;
    	}
    }
    

    But it is not working. Any idea?

You must be logged in to reply to this topic.

This topic is: not resolved