Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#20135 closed defect (bug) (invalid)

WP_User_Query() search Bug

Reported by: khoallaby Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3.1
Component: Users Keywords:
Focuses: Cc:


OP here ( http://wordpress.org/support/topic/wp_user_query-search-bug?replies=1 ), before i knew i could submit tickets to WP's trac.

for example I run

$query = new WP_User_Query( array( 'search' => 'sand' ) );

and get no results returned unless I set 'sand' to the exact match, like 'sandbox' (in my case).

var_dump below. Specifically looking at the 'query_where', where it should be user_login LIKE '%sand%' with the ampersands to actually query LIKE terms.

object(WP_User_Query)#5 (8) {
  array(0) {
  string(1) "0"
  string(30) "SQL_CALC_FOUND_ROWS wp_users.*"
  string(13) "FROM wp_users"
  string(67) "WHERE 1=1 AND (user_login LIKE 'sand' OR user_nicename LIKE 'sand')"
  string(23) "ORDER BY user_login ASC"
  array(15) {
    string(0) ""
    string(0) ""
    string(0) ""
    string(0) ""
    array(0) {
    array(0) {
    string(4) "sand"
    string(5) "login"
    string(3) "ASC"
    string(0) ""
    string(0) ""
    string(3) "all"
    string(0) ""

Change History (3)

#1 @scribu
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

For performance reasons, wildcards are disabled by default. You have to pass '*sand*' to enable them.

Last edited 4 years ago by scribu (previous) (diff)

#2 @khoallaby
4 years ago

thanks a lot! makes sense why they would be disabled. also just curious, would you need to escape an asterisk if that was part of the search term? like \*sand\*

#3 @scribu
4 years ago

The asterisks are special only at the beginning and the end of the search term.

For further questions, source code is your friend:


Note: See TracTickets for help on using tickets.