Search users with custom meta data

I’m looking for a way to search to make wordpress search for matches on a WC users billing-/shipping-company – but im not sure how to achive this.
I found out how i can do it with the most common user fields (ID, login, email & nicename).

Searching for common user data:

    $customers_query = new WP_User_Query( apply_filters( 'woocommerce_json_search_customers_query', array(
        'fields'         => 'all',
        'orderby'        => 'display_name',
        'search'         => '*' . $term . '*',
        'search_columns' => array( 'ID', 'user_login', 'user_email', 'user_nicename')
    ) ) );   

I tried also tried:

    $yoursearchquery = 'Andr';
    $users = new WP_User_Query(array(
        'search' => $yoursearchquery,
        'meta_query' => array(
            'relation' => 'OR',
                'key' => 'billing_last_name',
                'value' => $yoursearchquery,
                'compare' => 'LIKE'
                'key' => 'billing_first_name',
                'value' => $yoursearchquery,
                'compare' => 'LIKE'

but this only returns if i use the EXACT word i want it to search for – and not part of the word.

Read more here: Search users with custom meta data

Leave a Reply

Your email address will not be published. Required fields are marked *