Get all users with a specific role
-
The only forum and blog entries out there I have found that don’t use SQL to get a list of users with a specific role, use WP_User_Search. This is all well and good, but that function is specifically for use in a paginated list.
This is my ‘hack’ for getting ‘all’ of my users (of my new custom type):
function get_pianists(){ require_once( ABSPATH . '/wp-admin/includes/user.php' ); $wp_user_search = new WP_User_Search( '', '', 'pianists'); $wp_user_search->users_per_page = 1000; $wp_user_search->prepare_query(); $wp_user_search->query_sort = ' ORDER BY display_name'; $wp_user_search->query(); $wp_user_search->prepare_vars_for_template_usage(); $wp_user_search->do_paging(); return $wp_user_search->get_results(); }
Is there a better way? Or is this something worth working out a patch for?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Get all users with a specific role’ is closed to new replies.