WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As above guys, I'm trying to build an AJAX search that works within BuddyPress WITHOUT modifying core code, but that allows me to use a wildcard when I'm searching by username.

Any suggestions?

share|improve this question

closed as off-topic by Pieter Goosen, ialocin, kaiser Aug 7 '14 at 11:18

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

I found the following class in the add user autocomplete plugin . It extends the normal searcha and allows '*';

Example: $wp_user_search = new A2B_User_Query( array( 'search' => $s . '*' ) ) ;

class A2B_User_Query extends WP_User_Query { /** * @see WP_User_Query::get_search_sql() */ function get_search_sql( $string, $cols, $wild = false ) { $string = esc_sql( $string );

    // Always search all columns
    $cols = array(
        'user_email',
        'user_login',
        'user_nicename',
        'user_url',
        'display_name'
    );

    // Always do 'both' for trailing_wild
    $wild = 'both';

    $searches = array();
    $leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : '';
    $trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : '';
    foreach ( $cols as $col ) {
        if ( 'ID' == $col )
            $searches[] = "$col = '$string'";
        else
            $searches[] = "$col LIKE '$leading_wild" . like_escape($string) . "$trailing_wild'";
    }

    return ' AND (' . implode(' OR ', $searches) . ')';
}

}

share|improve this answer
    
+1. I wrote that plugin. It's intended for use in the Dashboard, but it could easily be adapted for frontend use. – Boone Gorges Mar 19 '12 at 14:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.