Think I finally figured it our for anyone trying to do this… the drop-down item will allow you to view members by the number of bbPress replies…
// ======================= add order options to members loop ============================
add_action( 'bp_members_directory_order_options', 'sbmar_add_sorting_options' );
function sbmar_add_sorting_options() { ?>
<option value="posts-desc">Number of Posts</option>
<?php
}
add_action( 'bp_pre_user_query', 'sbmar_pre_user_query' );
function sbmar_pre_user_query( $BP_User_Query ) {
// Only run this if one of our custom options is selected
if ( in_array( $BP_User_Query->query_vars['type'], array( 'posts-asc', 'posts-desc' ) ) ) {
global $wpdb;
// Adjust SELECT
$BP_User_Query->uid_clauses['select'] = "
SELECT $wpdb->posts.post_author AS id
FROM $wpdb->posts";
// Adjust WHERE
$BP_User_Query->uid_clauses['where'] = "WHERE $wpdb->posts.post_type = 'reply'";
// Adjust ORDER BY
$BP_User_Query->uid_clauses['orderby'] = " GROUP BY $wpdb->posts.post_author ORDER BY COUNT($wpdb->posts.post_author)";
// Adjust ORDER
$BP_User_Query->uid_clauses['order'] = 'DESC';
}
}