2

Is it possible to perform a WP_User_Query with multiple search queries? Something like:

$args = array (
    'search'    => '*example.com OR *abc.com',
    'search_columns' => array( 'user_email' )
);

or

$args = array (
    'search' => array(
        'relation' => 'OR',
            array(
                'search_columns'    => 'user_email',
                'search'            => '*example.com',
            ),
            array(
                'search_columns'    => 'user_email',
                'search'            => '*abc.com',
            )
        )
    );

then perform query:

    $user_query = new WP_User_Query( $args );

which would return users who's email domain are @example.com OR @abc.com.

6
  • A possible solution would be to create two separate queries which return just the user IDs and then combine these into a single array which is then fed in to a third query which includes only these IDs. Commented Apr 20, 2016 at 14:19
  • Have you tried it before posting the question?
    – Minh Tri
    Commented Apr 20, 2016 at 14:23
  • @Dan Yes, the first method returns no results (tries to explicitly match the search string I think) and the second method returns all users. Commented Apr 20, 2016 at 14:26
  • You can't because search parameter accepts a string only. You should try SQL queries instead.
    – Minh Tri
    Commented Apr 20, 2016 at 14:31
  • 1
    @mistertaylor you seem to answer your own question there :) run multiple queries and combine.
    – Rarst
    Commented Apr 20, 2016 at 14:35

0

Your Answer

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

Browse other questions tagged or ask your own question.