Add a filter on bp_core_search_users_count_sql and bp_core_search_users_sql with an extra parameter
pd.field_id=1 and pd.value LIKE
Hi Manoj,
Thanks for your quick response. I’m a a dumbo. Could you please explain where exactly should I make the changes?
I don’t want to encourage you to do hard-coded changes, but if you want to, here are the instructions
1. Open wp-content->plugins->buddypress->bp-core->bp-core-classes.php
2. replace line 247 and 248 by following code
$total_users_sql = apply_filters( 'bp_core_search_users_count_sql', "SELECT DISTINCT count(u.ID) as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE pd.field_id=1 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC", $search_terms );
$paged_users_sql = apply_filters( 'bp_core_search_users_sql', "SELECT DISTINCT u.ID as user_id FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE pd.field_id=1 AND pd.value LIKE '%%$search_terms%%' ORDER BY pd.value ASC{$pag_sql}", $search_terms, $pag_sql );
in above code “pd.field_id=1” should be the id of Full Name field ( I think its 1 )
You’d be better off replacing the SQL using the two filters on those queries.
For example
function my_custom_sql() {
global $wpdb;
return $wpdb->prepare( "My Custom Query" );
}
add_filter( 'bp_core_search_users_sql', 'my_custom_sql' );
The same goes for the count SQL.