1

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.

  • 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. – mistertaylor Apr 20 '16 at 14:19
  • Have you tried it before posting the question? – MinhTri Apr 20 '16 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. – mistertaylor Apr 20 '16 at 14:26
  • You can't because search parameter accepts a string only. You should try SQL queries instead. – MinhTri Apr 20 '16 at 14:31
  • 1
    @mistertaylor you seem to answer your own question there :) run multiple queries and combine. – Rarst Apr 20 '16 at 14:35

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.