Get current custom user taxonomy

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?

2 Answers
2

Try this suggestion:

$user_id = get_current_user_id();  // Get current user Id
$user_groups = wp_get_object_terms($user_id, 'user-group', array('fields' => 'all_with_object_id'));  // Get user group detail
foreach($user_groups as $user_gro)
{
    echo $user_gro->name; // Get current user group name
    echo $user_gro->taxonomy; // get current user taxonomy 
}

Leave a Comment