#20135 closed defect (bug) (invalid)
WP_User_Query() search Bug
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.3.1 |
Component: | Users | Keywords: | |
Focuses: | Cc: |
Description
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) { ["results"]=> array(0) { } ["total_users"]=> string(1) "0" ["query_fields"]=> string(30) "SQL_CALC_FOUND_ROWS wp_users.*" ["query_from"]=> string(13) "FROM wp_users" ["query_where"]=> string(67) "WHERE 1=1 AND (user_login LIKE 'sand' OR user_nicename LIKE 'sand')" ["query_orderby"]=> string(23) "ORDER BY user_login ASC" ["query_limit"]=> NULL ["query_vars"]=> array(15) { ["blog_id"]=> int(1) ["role"]=> string(0) "" ["meta_key"]=> string(0) "" ["meta_value"]=> string(0) "" ["meta_compare"]=> string(0) "" ["include"]=> array(0) { } ["exclude"]=> array(0) { } ["search"]=> string(4) "sand" ["orderby"]=> string(5) "login" ["order"]=> string(3) "ASC" ["offset"]=> string(0) "" ["number"]=> string(0) "" ["count_total"]=> bool(true) ["fields"]=> string(3) "all" ["who"]=> string(0) "" } }
Change History (3)
#1
@
13 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
#2
@
13 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
@
13 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:
http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/user.php#L465
For performance reasons, wildcards are disabled by default. You have to pass
'*sand*'
to enable them.