0

How to use something like meta_query but for fields?

This is my short code to understand me:

$args = array(
    'meta_query' => array(
        array(
            'key' => 'nickname',
            'value' => $search,
            'compare' => 'LIKE'
        )
    )
);
$all_users = get_users($args);

How to make it working but by searching on user_login table not nickname meta?

2
  • Well, I'm not sure what you are trying to achieve. Would you please elaborate your question a little bit more ? And what are referring to by How to make it working but by searching on user_login table not nickname meta? ???
    – CodeMascot
    Commented Sep 27, 2017 at 2:06
  • @the_dramatist I need to use something like meta_query but by searching the fields like user_login or user_login not searching the metas, Understand me?
    – Trello
    Commented Sep 27, 2017 at 2:14

1 Answer 1

0

get_users is a wrapper for WP_User_Query, which offers some additional parameters for searching specific columns.

$args = array(
    'search'         => $search,
    'search_columns' => array( 'user_login' )
);
$user_query = new WP_User_Query( $args );
2
  • Milo, I already try this by using your code this will be searching for the search word but my codes are to get the value and try to search it. Example if I search for mil without o with you codes it will be not working because that I use meta value. Hope you understand me and have a solution.
    – Trello
    Commented Sep 27, 2017 at 3:52
  • Your search term needs wildcards if it's not an exact match, like '*' . $search . '*'. See the Search Parameters section for WP_User_Query.
    – Milo
    Commented Sep 27, 2017 at 4:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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