= 0 ) { /** * by default the ORDER BY is on um.meta_value * but our meta_value is umm.meta_value, so we need to change this! * you can also change the order (DESC or ASC) */ $sql[0] = 'ORDER BY umm.meta_value DESC'; $sql['select_meta'] = ', umm.meta_value as position'; $query = join( ' ', (array)$sql ); } return $query; } /** * we must also filter the count request for pagination * that BP_Core_User::get_users will play */ add_filter('bp_core_get_total_users_sql', 'bp_imath_experimental_umeta_filter_count', 10, 2); function bp_imath_experimental_umeta_filter_count($query, $sql) { /* check the meta before modifying the query...*/ if( !empty($sql['where_meta']) && strpos( $sql['where_meta'], 'bpci_latest_address') >= 0 ) { // you can change order by pref (DESC or ASC) $sql[1] = 'ORDER BY umm.meta_value DESC'; $sql['select_meta'] = ''; $query = join( ' ', (array)$sql ); } return $query; } /** * as i play directly on the members directory * i need to filter the ajax querystring to add the meta_key argument * meta_key=bpci_latest_address */ add_filter( 'bp_dtheme_ajax_querystring', 'bp_imath_experimental_dtheme_ajax_query', 10, 7 ); function bp_imath_experimental_dtheme_ajax_query( $query_string, $object, $object_filter, $object_scope, $object_page, $object_search_terms, $object_extras ){ /* check filter before modifying querystring...*/ if( $object_filter == 'bpci_latest_address' ) { if( strpos($query_string, 'type=bpci_latest_address&action=bpci_latest_address') >= 0 ) $query_string = str_replace('type=bpci_latest_address&action=bpci_latest_address', 'meta_key=bpci_latest_address', $query_string); } return $query_string; } /** * now as i added 'umm.meta_value as position' * in the select query, let's use this value * instead of using echo get_user_meta( $user_id ,'bpci_latest_address', true) */ function bp_imath_experimental_the_member_position() { echo bp_imath_experimental_get_the_member_position(); } function bp_imath_experimental_get_the_member_position(){ global $members_template; return apply_filters('bp_imath_experimental_get_the_member_position', $members_template->member->position); } /** * finally let's display the position or score in your case.. * by using the hook just after the latest activity in the members-loop template */ add_action('bp_directory_members_item', 'bp_imath_experimental_finally_display'); function bp_imath_experimental_finally_display(){ ?>