Title: Get current users sub-group
Last modified: September 1, 2016

---

# Get current users sub-group

 *  Resolved [runofthemill](https://wordpress.org/support/users/runofthemill/)
 * (@runofthemill)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/get-current-users-sub-group/)
 * Hi there – great plugin! I’m having a hard time understanding the API documentation;
   I’m trying to write a filter that lists the single (admin-enforced) group a user
   belongs to within a specific parent group, in order to modify a menu link.
 * Group hierarchy:
    – Regions |- Region I |- Region II |- Region III |- Region 
   IV
 * If user is in Region I, function returns example.com/region-i, and if user is
   in region IV, function returns example.com/region-iv
 * I’m pretty sure I could figure out if I was using a flat group structure, but
   I’m not sure how to deal with the parent level
 * Any suggestions on how to tackle?
 * Thanks!
 * [https://wordpress.org/plugins/groups/](https://wordpress.org/plugins/groups/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [runofthemill](https://wordpress.org/support/users/runofthemill/)
 * (@runofthemill)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/get-current-users-sub-group/#post-7636094)
 * Nevermind, figured it out!
 *     ```
       function dynamic_home_link( $args ) {
         $homepage = '';
         $groups_user = new Groups_User( get_current_user_id() );
         $user_groups = $groups_user->groups;
         foreach ($user_groups as $user_group) {
           if ($user_group_id = $user_group->group->parent_id) {
             if ($user_group_id = 2) {
               $homepage = strtolower(str_replace(" ", "-", $user_group->group->name));
             }
           }
         }
         return str_replace('user_homepage', $homepage, $args);
       }
       add_filter( 'wp_nav_menu', __NAMESPACE__ . '\\dynamic_home_link' );
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Get current users sub-group’ is closed to new replies.

 * ![](https://ps.w.org/groups/assets/icon-256x256.png?rev=983146)
 * [Groups](https://wordpress.org/plugins/groups/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/groups/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/groups/)
 * [Active Topics](https://wordpress.org/support/plugin/groups/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/groups/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/groups/reviews/)

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [filter](https://wordpress.org/support/topic-tag/filter/)

 * 1 reply
 * 1 participant
 * Last reply from: [runofthemill](https://wordpress.org/support/users/runofthemill/)
 * Last activity: [9 years, 10 months ago](https://wordpress.org/support/topic/get-current-users-sub-group/#post-7636094)
 * Status: resolved