I’m using the plugin User Groups which lets me group users with categories. The plugin is working essentially the same as using the manual method (custom user taxonomies) described by Justin Tadlock here.
On author.php I want to list the taxonomies the currently viewed user belongs to, and each list item should link to the taxonomy term page.
I use the following code to get current user ID and retrieve custom field values from the profile page:
<?php // Get current author
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
?>
And I use the following code to list the custom user taxonomies:
<?php // List custom user taxonomies
wp_list_categories('taxonomy=user-group');
?>
“taxonomy=user-group” is fetching all of the terms created within the plugin.
Here’s a way to get current post taxonomies, but I’m looking to change it to custom user taxonomies.
Is there a way for me to change wp_list_categories() to only display the taxonomies I want? Should I be looking for another approach?
Try this suggestion:
Ok, problem solved. I ditched the plugin and got another one called User Taxonomies. It does all the boring part of creating custom taxonomies (saving fields etc.) You will do just as well by writing it all yourself, but i wanted to keep my code clean.
After installing the plugin I registered my custom taxonomies manually like described on the plugin page, but added
hierarchy => true
to make the taxonomy act like categories instead of like tags. To allow multi selection on the profile-page i added this code to the plugin document user-taxonomies.php:Then I had to change the saving of fields with this function (added to the same file:
To show the taxonomy terms which the user belongs to, I used the following snippet:
Hope this helps someone. Credit goes to Timothy Wood and benjaminniess.