[wp-hackers] WP User Query with two meta keys
Simon Dunton - WP Sites
simon at wpsites.co.uk
Wed May 2 12:31:14 UTC 2012
Yesterday I did some work on building SQL to search for a large number of users to be deleted from a WP multisite. Might be of interest to you:
//get a list of users with a specia meta_key (birthday party reminder)
$users_with_meta = $wpdb->get_results('select '.$wpdb->usermeta.'.user_id, '.$wpdb->users.'.display_name, '.$wpdb->users.'.user_email' .
' from '.$wpdb->usermeta.', '.$wpdb->users.
' where '.$wpdb->usermeta.'.user_id='.$wpdb->users.'.ID and'.
' meta_key like "dob_%"'.
' group by user_id');
//a list of admin users from all blogs in the network
$users_admin = $wpdb->get_results('select '.$wpdb->usermeta.'.user_id, '.$wpdb->users.'.display_name, '.$wpdb->users.'.user_email' .
' from '.$wpdb->usermeta.', '.$wpdb->users.
' where '.$wpdb->usermeta.'.user_id='.$wpdb->users.'.ID and'.
' meta_key like "wp%_capabilities" and'.
' meta_value like "%admin%"'.
' group by user_id');
Simon
WP Sites Limited
On 2 May 2012, at 13:00, wp-hackers-request at lists.automattic.com wrote:
> Message: 2
> Date: Tue, 01 May 2012 17:27:51 +0100
> From: Robert Lusby <nanogwp at gmail.com>
> Subject: [wp-hackers] WP User Query with two meta keys
> To: wp-hackers at lists.automattic.com
> Message-ID: <4FA00F07.2030601 at gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Is it possible to select a user matching "two" meta keys and values, in
> WP User Query?
>
> E.g. select users where:
> plant = "oak"
> AND
> town = "town"
>
> Much like WP_Query's meta_query.
>
> If not - how would you go about this?
>
> Thanks,
> Rob
More information about the wp-hackers
mailing list