• Hello !

    I had a taxonomy for users in my website. I use this taxonomy for users and for certain of my custom post type.

    So I add a view in admin to display a table with how many posts there is in each term of my taxonomy and also how many users.

    I want to add a link to a page in the admin where I can see all my users who are in a specific term of my taxonomy.

    I explain : for example, for the posts, there is an URL like this :
    “edit.php?taxonomy=term&post_type=my_post_type”
    So I can see all the post type “my_post_type” in the category “term” of my taxonoy.

    I would like to do the same thing with users.

    Is it possible ?

    Thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You should be able to leverage the default WP_Users_list_Table to display only users with a specific taxonomy term. Use the ‘manage_users_extra_tablenav’ action to output a new dropdown input field and filter submit button.

    When the form is submitted to users.php, the dropdown field’s name and selection will be added as an URL query string. users.php will have no idea how to handle this added query string. It should ignore it. You can then hook “users_pre_query” action to alter the SQL’s various query clauses to cause the requested taxonomy term (from $_GET) to limit query results.

    This is a rather convoluted approach because users don’t normally have taxonomy terms associated with it, so the usual user query vars cannot be used. It’d be easier to filter users by a custom capability, even if that capability is not otherwise used anywhere. Then you could just set the “capability” query var instead of having to mess with SQL clauses.

Viewing 1 replies (of 1 total)

The topic ‘Display filtered view of users by taxonomy’ is closed to new replies.