bp_core_search_users_sql

Filters the SQL used to query for searched users.

Description

Parameters (3)

0. $wpdb_prepare_select_distinct_u_id_as_id_u_user_registered_u_user_nicename_u_user_login_u_user_email_from_wpdb_users_u_left_join_bp_profile_table_name_data_pd_on_u_id_pd_user_id_where_status_sql_and_pd_value_like_s_order_by_pd_value_asc_pag_sql_search_terms_like (string)
The wpdb prepare select distinct u id as id u user registered u user nicename u user login u user email from wpdb users u left join bp profile table name data pd on u id pd user id where status sql and pd value like s order by pd value asc pag sql search terms like.
1. $search_terms (unknown)
The search terms.
2. $pag_sql (unknown)
The pag sql.

Usage

To run the hook, copy the example below.
  1. $wpdb_prepare_select_distinct_u_id_as_id_u_user_registered_u_user_nicename_u_user_login_u_user_email_from_wpdb_users_u_left_join_bp_profile_table_name_data_pd_on_u_id_pd_user_id_where_status_sql_and_pd_value_like_s_order_by_pd_value_asc_pag_sql_search_terms_like = apply_filters( 'bp_core_search_users_sql', $wpdb_prepare_select_distinct_u_id_as_id_u_user_registered_u_user_nicename_u_user_login_u_user_email_from_wpdb_users_u_left_join_bp_profile_table_name_data_pd_on_u_id_pd_user_id_where_status_sql_and_pd_value_like_s_order_by_pd_value_asc_pag_sql_search_terms_like, $search_terms, $pag_sql ); 
  2.  
  3. if ( !empty( $wpdb_prepare_select_distinct_u_id_as_id_u_user_registered_u_user_nicename_u_user_login_u_user_email_from_wpdb_users_u_left_join_bp_profile_table_name_data_pd_on_u_id_pd_user_id_where_status_sql_and_pd_value_like_s_order_by_pd_value_asc_pag_sql_search_terms_like ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the bp_core_search_users_sql callback 
  2. function filter_bp_core_search_users_sql( $wpdb_prepare_select_distinct_u_id_as_id_u_user_registered_u_user_nicename_u_user_login_u_user_email_from_wpdb_users_u_left_join_bp_profile_table_name_data_pd_on_u_id_pd_user_id_where_status_sql_and_pd_value_like_s_order_by_pd_value_asc_pag_sql_search_terms_like, $search_terms, $pag_sql ) { 
  3. // make filter magic happen here... 
  4. return $wpdb_prepare_select_distinct_u_id_as_id_u_user_registered_u_user_nicename_u_user_login_u_user_email_from_wpdb_users_u_left_join_bp_profile_table_name_data_pd_on_u_id_pd_user_id_where_status_sql_and_pd_value_like_s_order_by_pd_value_asc_pag_sql_search_terms_like
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'bp_core_search_users_sql', 'filter_bp_core_search_users_sql', 10, 3 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'bp_core_search_users_sql', 'filter_bp_core_search_users_sql', 10, 3 ); 

Defined (1)

The filter is defined in the following location(s).

/bp-core/classes/class-bp-core-user.php  
  1. $paged_users_sql = apply_filters( 'bp_core_search_users_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE %s ORDER BY pd.value ASC{$pag_sql}", $search_terms_like ), $search_terms, $pag_sql );