Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Sort Members Alphabetically by Default

@kmw1130

Participant

I added this to members-loop:

<?php /* Querystring is set via AJAX in _inc/ajax.php - bp_dtheme_object_filter() */ ?>
<?php do_action( 'bp_before_members_loop' ) ?>

<?php
if ( bp_ajax_querystring( 'members' ) ==""){
$queryString = "type=alphabetical&action=alphabetical&page=1";}
else {$queryString = bp_ajax_querystring( 'members' );}
?>

<?php if ( bp_has_members( $queryString) ) : ?>

<strong>Index.php</strong>

<select id="members-order-by">
	<?php if ( bp_is_active( 'xprofile' ) ) : ?>
		<option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
	<?php endif; ?>
		<option value="active"><?php _e( 'Last Active', 'buddypress' ); ?></option>
		<option value="newest"><?php _e( 'Newest Registered', 'buddypress' 

Functions.php (child theme)
/** Sort alphabetical name listings by lastname */
function alphabetize_by_last_name( $bp_user_query ) {
    if ( 'alphabetical' == $bp_user_query->query_vars['type'] )
        $bp_user_query->uid_clauses['orderby'] = "ORDER BY substring_index(u.display_name, ' ', -1)";
}
add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' );

Is that correct?

Thanks
Kim

Skip to toolbar