Skip to:
Content
Pages
Categories
Search
Top
Bottom

Limiting search to ‘Full Name’ field


  • thebigk
    Participant

    @thebigk

    Hello,

    I’d like to limit the default bp member search functionality to ‘Full Name’. I’m using BP 1.0.

    How can I do this?

Viewing 4 replies - 1 through 4 (of 4 total)

  • talk2manoj
    Participant

    @talk2manoj

    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


    thebigk
    Participant

    @thebigk

    Hi Manoj,

    Thanks for your quick response. I’m a a dumbo. Could you please explain where exactly should I make the changes? :(


    talk2manoj
    Participant

    @talk2manoj

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Limiting search to ‘Full Name’ field’ is closed to new replies.
Skip to toolbar