@imuhammad
9 years, 2 months ago
// code for functions.php
function xfield_member_filter( $field_name, $field_value = '' ) { if ( empty( $field_name ) ) return ''; global $wpdb; $field_id = xprofile_get_field_id_from_name( $field_name ); if ( !empty( $field_id ) ) $query = "SELECT user_id, value FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id . " ORDER BY value" ; else return ''; // var_dump($query); die; if ( $field_value != '' ) $query .= " AND value LIKE '%" . $field_value . "%'"; /* LIKE is slow. If you're sure the value has not been serialized, you can do this: $query .= " AND value = '" . $field_value . "'"; */ $custom_ids = $wpdb->get_col( $query ); if ( !empty( $custom_ids ) ) { // convert the array to a csv string $custom_ids_str = 'include=' . implode(",", $custom_ids); return $custom_ids_str; } else return ''; } function alphabetize_by_last_name( $bp_user_query ) { ; if ( 'alphabetical' == $bp_user_query->query_vars['type'] ) { $bp_user_query->uid_clauses['orderby'] = "ORDER BY FIELD(u.ID," . $bp_user_query->query_vars['include'] . ")"; $bp_user_query->uid_clauses['order'] = ""; var_dump($bp_user_query); } } add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' ); // code for loop <?php if ( bp_has_members( xfield_member_filter( 'Last Name' ).'&type=alphabetical' ) ) : ?>