Skip to content

searchColumns parameter in users Query doesn't work. #2419

@developerfan1219

Description

@developerfan1219

I would like to query users by email and nickname.
query will be like this:

Where
   email like '%test%' OR
   nickname like '%test%'

To Test

query NewQuery {
  users(where: {search: "test", searchColumns: [NICENAME, EMAIL]}) {
    edges {
      node {
        firstName
        lastName
        name
        nickname
        email
      }
    }
  }
}

In get_query of UserConnectionResolver, $this->query_args before running query is below:

{ ["count_total"]=> bool(false) ["graphql_args"]=> array(1) { ["where"]=> array(2) { ["search"]=> string(4) "test" ["searchColumns"]=> array(1) { [0]=> string(8) "nicename" } } } ["graphql_cursor_offset"]=> int(0) ["graphql_cursor_compare"]=> string(1) "<" ["graphql_after_cursor"]=> NULL ["graphql_before_cursor"]=> NULL ["number"]=> int(11) ["search"]=> string(6) "*test*" ["search_columns"]=> array(1) { [0]=> string(8) "nicename" } ["fields"]=> string(2) "ID" ["has_published_posts"]=> bool(true) ["orderby"]=> string(10) "user_login" ["order"]=> string(3) "ASC" }

the query string after running query:

SELECT wp_users.ID FROM wp_users WHERE 1=1 AND wp_users.ID IN ( SELECT DISTINCT wp_posts.post_author FROM wp_posts WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type IN ( 'post', 'page', 'attachment' ) ) AND (user_login LIKE '%test%' OR user_url LIKE '%test%' OR user_email LIKE '%test%' OR user_nicename LIKE '%test%' OR display_name LIKE '%test%') ORDER BY user_login ASC, wp_users.ID DESC LIMIT 0, 11

image

I would like to get the query string like this.

SELECT wp_users.ID FROM wp_users WHERE 1=1 AND wp_users.ID IN ( SELECT DISTINCT wp_posts.post_author FROM wp_posts WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type IN ( 'post', 'page', 'attachment' ) ) AND (user_email LIKE '%test%' OR user_nicename LIKE '%test%') ORDER BY user_login ASC, wp_users.ID DESC LIMIT 0, 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    component: queryRelating to GraphQL Queriesobject type: userRelating to the User Typestatus: in progressCurrently being worked ontype: bugIssue that causes incorrect or unexpected behavior

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions