Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * as i test on bp members directory
- * i first add a new option in member filter
- * it could be the score user meta_key in your case
- * in mine it's the latest geo position user meta_key (bpci_latest_address)
- */
- add_action( 'bp_members_directory_order_options', 'bp_imath_experimental_add_umeta_in_filter_list');
- function bp_imath_experimental_add_umeta_in_filter_list() {
- ?>
- <option value="bpci_latest_address"><?php _e( 'Latest Geo Postion', 'buddypress' ); ?></option>
- <?php
- }
- /**
- * the main trick is to directly apply a filter on the request
- * that BP_Core_User::get_users will play
- */
- add_filter('bp_core_get_paged_users_sql', 'bp_imath_experimental_umeta_filter_select', 10, 2);
- function bp_imath_experimental_umeta_filter_select($query, $sql) {
- /* check the meta before modifying the query...*/
- if( !empty($sql['where_meta']) && strpos( $sql['where_meta'], 'bpci_latest_address') >= 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(){
- ?>
- <div class="whatever"><?php bp_imath_experimental_the_member_position();?></div>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement