The first issue as I see it is that you are using the_terms
function. If you actually look in the source code you will see that after a couple of other function calls the whole thing fails because eventually the function get_the_terms
is called which checks if the ID
you are passing is a valid post. Sometimes this might work though if the user_id
might happen to match a post_id
.
You might be interested to check the wp_get_object_terms
function instead.
Regarding the taxonomy page problem. You are registering the taxonomy as Roles
with capital R
. The template file would have to contain the exact same name: taxonomy-Roles.php
. Also, on the taxonomy page you don’t have a loop. You need to query for the object_id
, the object
itself and then fetch users that have that association of term_id
and corresponding taxonomy
. You can do this with get_objects_in_term
.
As Tom J Nowell pointed out (even though the documentation
doesn’t include the role
term as reserved). if you have users registration enabled and if you have exotic users that would pick roles
as the username you will get a conflict regarding the author
query (author_name
query variable). Due to this you may want to filter that username.