Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Member loop – Create member list via custom field + custom order

@amandafrench

Participant

Never mind! I’ve found a fabulous solution that has gotten me out of SQL query hell. Again, if anyone else is trying to sort a Members Directory, here’s what I did:

1) Put it in a table, not a list (I had done this anyway, since I wanted a single-page directory that displayed xprofile fields horizontally) — make sure it has a <th> table header row;
2) Install the plugin Table Sorter https://wordpress.org/plugins/table-sorter/ and add the class “tablesorter” to the table.

Et voilĂ ! I commented out the sort type dropdown in members/index.php starting with
<div class="item-list-tabs" id="subnav" aria-label="<?php esc_attr_e( 'Members directory secondary navigation', 'buddypress' ); ?>" role="navigation">
all the way through

<?php
/**
 * Fires inside the members directory member order options.
 *
 * @since 1.2.0
 */
do_action( 'bp_members_directory_order_options' ); ?>
</select>
</li>
</ul>
</div>

and I made sure that the default single page list showed all users alphabetically by default in members-loop.php

<?php if ( bp_get_current_member_type() ) : ?>
	<p class="current-member-type"><?php bp_current_member_type_message() ?></p>
<?php endif; ?>

<?php if ( bp_has_members( bp_ajax_querystring( 'members' ) . '&per_page=500' . '&exclude=1,2,3,4,6' . '&type=alphabetical') ) : ?>

And then all I had to do was add that tablesorter class to the table as required by the tablesorter plugin, and I got a nice dynamic table with sortable columns, which can also be sorted by multiple criteria by holding down the Shift key on the second column. I set the initial sort order with parameters that select the column by number, as described at http://tablesorter.com/docs/example-option-sort-list.html and elsewhere.

<table id="members-list" class="tablesorter {sortlist:[[4,0], [3,0], [2,0], [1,0], [0,0]]}" aria-live="assertive" aria-relevant="all">

Yay.

Skip to toolbar