Combining Meta_Query key values for one array

What if you use IN operator and split the search term in a words array:

$args = array(
    'role'           => 'Subscriber',
    'meta_query'     => array(
        array(
                'key'     => 'membership_class',
                'value'   => 'Full',
                'compare' => '=',
                'type'    => 'CHAR',
            ),
        array(
            'relation' => 'OR',
            array(
                'key'     => 'first_name',
                'value'   => explode( ' ', $usersearch ),
                'compare' => 'IN'
            ),
            array(
                'key'     => 'last_name',
                'value'   => explode( ' ', $usersearch ),
                'compare' => 'IN'
            ),
            array(
                'key'     => 'personal_city',
                'value'   => $usersearch,
                'compare' => 'LIKE',
                'type'    => 'CHAR',
            ),
            array(
                'key'     => 'personal_province',
                'value'   => $usersearch,
                'compare' => 'LIKE',
                'type'    => 'CHAR',
            ),
            array(
                'key'       => 'treatments',
                'value'     => $usersearch,
                'compare'   => 'LIKE',

            ),



        ),

    ),
);

Leave a Comment