1

I am trying to create a search of users to search for them using their first name, last name, billing phone, ID, or email. I have the following code written, but it does not pull in the correct data. I think that it is not searching the meta_query and I do not know how to make it search it as well. Any help or suggestions would be appreciated.

$users = new WP_User_Query( array(
            'role'           => 'customer',
            'search'         => "*".$search_string."*",
            'search_columns' => array(
              'ID',
              'user_login',
              'user_nicename',
              'user_email',
            ),
            'meta_query' => array(
                'relation' => 'OR',
                array(
                    'key'     => 'first_name',
                    'value'   => $search_string,
                    'compare' => 'LIKE'
                ),
                array(
                    'key'     => 'last_name',
                    'value'   => $search_string,
                    'compare' => 'LIKE'
                ),
                array(
                    'key'     => 'billing_phone',
                    'value'   => $search_string,
                    'compare' => 'LIKE'
                )
            )
        ) );

        $players = $users->get_results();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.