I added some custom taxonomy to a CPT with:
register_taxonomy( \'sport\', \'activity\', [
\'label\' => \'Sport\',
\'rewrite\' => [ \'slug\' => \'sport\'],
\'hierarchical\' => true
]);
and this works fine. The taxonomy also shows up in the admin menu, as a subpage for activity.
Then I wanted to do the same for the users:
register_taxonomy( \'team\', \'user\', [
\'label\' => \'Team\',
\'rewrite\' => [ \'slug\' => \'team\'],
\'hierarchical\' => true
]);
However this did not work for me, the taxonomy did not show up in the admin menu.
After some research, I could make it appear with this code
function add_user_tax_menu() {
$tax = get_taxonomy( \'team\' );
add_users_page(
esc_attr( $tax->labels->menu_name ),
esc_attr( $tax->labels->menu_name ),
$tax->cap->manage_terms,
\'edit-tags.php?taxonomy=\' . $tax->name
);
}
add_action(\'admin_menu\', \'add_user_tax_menu\');
But it still does not work properly. For example if click on the link in the count
column, I end up in the posts sections, with no posts listed.
I guess I have to somehow tell WP that the type is user
and not post
, but I cannot figure out how.
I also tried using \'edit-tags.php?taxonomy=\' . $tax->name . \'&post_type=user\'
instead, but that didn\'t work either (maybe because user isn\'t a post type?).
Update
With the help of the answer posted by @saqib-ali and the tutorial mentioned in the comment, I got somewhat closer to to a solution. However, I still cannot see which users are assigned to a team
. When I click on the link in the Count
column (see screenshot) I end up back in the posts
section of the admin panel.
The link points to
.../wp-admin/edit.php?team=team-a
My guess is, that it needs to be changed to
.../wp-admin/users.php?team=team-a
according to the mentioned tutorial, this might be done with the manage_circle_custom_column
hook. But I could not find a hook like that in the WP doc (only manage_posts_custom_column
). So maybe that hook doesn\'t exist (anymore)?
And then I would probably also need to add a filter hook that filters users by the taxonomy in the query parameter. Similar to how it works for the role
.../wp-admin/users.php?role=administrator
I couldn\'t yet find the appropriate hook for either task.