I am developing a plugin for wordpress and I want to get list of users with role1 or role2 or role3 or role4. I use the code below to get users with role1 but I don’t know how should I change it to get users of more than 1 role.
$jobholders = get_users( 'orderby=nicename&role=jobholder' );
I thought that using a MySQL wildcard would work because the query in the class
WP_User_Query
is built with LIKE, but it doesn’t:get_users(array('role' => 'job%'))
.The solution has to be with the action hook
pre_user_query
:It considers that we have two roles,
jobseeker
andjobholder
, and to search for both we would use this call, with an inexistant role but with a string that both contain (no wildcards):get_users(array('role' => 'job');
. This makesquery_where
to be like this:wp_capabilities
is a serialized array, so it looks for a perfect match forjob
between wildcards.