From my previous question How to create and retrieve data from a special registration form? I would like to know how do I list in the backend all users that were assigned to a custom role? Is it possible to put them in a separate admin page?
Leave a Reply
You must be logged in to post a comment.
User queries
There is a
WP_User_Query
, analogous toWP_Query
for posts:Usually this returns an array of row objects from the user table:
However you can specify it to instead return an array of WP_User objects by including
'fields'=>'all_with_meta'
in the array passed toWP_User_Query
.Register Admin Page
To register admin menus you need to hook a function onto
'admin_menu'
which callsadd_submenu_page
(oradd_menu_page
if you want a top-level page). See the Codex.In this case adding the page under the ‘users’ tab seems appropriate, and the hook for that is ‘users.php’.
If you wanted to have a table on this page, listing only users of a specific role, you may want to consider looking at the WP_List_Table plug-in. It’s not really a plug-in but an example of how to use the
WP_List_Table
class. (Using this you could include extra columns for user meta data etc.). (Note, however, the default user table does already allow you to filter by user).