Hi Janet,
Could you please detail how you are ordering the members directory by an extended profile field? Are you using a plugin or some custom code?
Andrea,
I am using some custom code in the functions.php file. I have extended bp_members_directory_order_options to add my Profile Search fields. And I have extended bp_pre_user_query to add the sql code to sort based on those fields. I think that is where it is going wrong, that I have the full members directory and not what the Profile Search created but I am not seeing where else to hook that in.
Thanks for your help.
Janet,
If you wish you can send me your code, and if I’m lucky I might find the way to make it work with BP Profile Search. My email is andrea@dontdream.it
Andrea – Thank you so much for your help!! For anyone that might alo be having this problem I will include my function below with the update that Andrea provided.
// sort ajax members by HSF profile information
function users_sortby_hsf( $object ) {
global $wpdb, $bp;
// Only run this if hsf option is selected
if ( ! in_array( $object->query_vars[‘type’], array( ‘AwardYear’, ‘Residence’, ‘Institution’, ‘Major’ ) ) )
return;
$field_id = $wpdb->get_var( $wpdb->prepare( “SELECT id FROM {$bp->profile->table_name_fields} WHERE name = %s”, $object->query_vars[‘type’] ) );
$object->uid_name = ‘user_id’;
$object->uid_table = $bp->profile->table_name_data;
$object->uid_clauses[‘select’] = “SELECT u.{$object->uid_name} as id FROM {$object->uid_table} u”;
$object->uid_clauses[‘where’] = ” WHERE ” . $wpdb->prepare( “u.field_id = %d”, $field_id );
// code for BP Profile Search
$include = $object->query_vars[‘include’];
if (!empty ($include))
$object->uid_clauses[‘where’] .= ” AND u.{$object->uid_name} IN ($include)”;
// end code for BP Profile Search
$object->uid_clauses[‘orderby’] = “ORDER BY u.value”;
$object->uid_clauses[‘order’] = “ASC”;
}
add_action( ‘bp_pre_user_query’, ‘users_sortby_hsf’ );