Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore search string case when using WP_User_Query?

Tags:

php

wordpress

Using the following code, how can I do the search by ignoring the case of the field in the database :

    $args = array(
    'meta_query' => array(
        'relation' => 'OR',
        array(
            array(
            'key'     => 'province',
            'value'   => 'kzn',
            'compare' => '='
            ),
        )
    )
 );
$user_query = new WP_User_Query( $args );

In the above example, 'kzn' is stored as KZN in the database. The input search string can be 'Kzn', or 'kZn... etc. The value to search for can also be a mixed bag as far as it's case goes. So I guess what I am looking for is a war to search for uppercase(databasefield) in the value field, if that makes sense.

Thank you.

like image 420
Gavin Simpson Avatar asked Sep 17 '25 12:09

Gavin Simpson


1 Answers

Got it.

(
    'key'     => 'province',
    'value'   => ('^'.$province),
    'compare' => 'REGEXP'
);
like image 127
Gavin Simpson Avatar answered Sep 20 '25 02:09

Gavin Simpson