Title: do_shortcode groups_join not working in hook
Last modified: January 31, 2019

---

# do_shortcode groups_join not working in hook

 *  Resolved [ostetaan](https://wordpress.org/support/users/ostetaan/)
 * (@ostetaan)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/do_shortcode-groups_join-not-working-in-hook/)
 * Hi!
 * I am trying to add subscriber users automatically to the same group of the contributor
   after subscriber users have been created, but do_shortcode in hook seems not 
   working. Please help!!!
 * This is my code
 *     ```
       add_action( 'user_register', array($this, 'create_user'), 10, 1 );
   
       function create_user($user_id) {
   
       global $wpdb;
   
       	//Get current user group id from database
   
       	$getValue = $wpdb->get_results("SELECT user_id , wp_groups_group.group_id, wp_groups_user_group.group_id, name  FROM  wp_groups_group, wp_groups_user_group WHERE wp_groups_group.group_id =  wp_groups_user_group.group_id");
   
       	$currentUser = wp_get_current_user();
       	$currentUserID = $currentUser->ID;
       	$groupID = "";
       	$groupName = "";
       	foreach ($getValue as $key => $value) {
       		if ($currentUserID == $value->user_id  && $value->group_id > 1) {
       			$groupID = $value->group_id;
       			$groupName = $value->name;
   
       		}else{
       		}
       	}
   
       	do_shortcode('[groups_join group="'.$groupName.'"]');
   
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [gtsiokos](https://wordpress.org/support/users/gtsiokos/)
 * (@gtsiokos)
 * [7 years, 3 months ago](https://wordpress.org/support/topic/do_shortcode-groups_join-not-working-in-hook/#post-11222783)
 * Hi ostetaan,
 * Although I haven’t checked your code, you can add a user to a group with the 
   method [Groups_User_Group::create( $map )](http://api.itthinx.com/groups/source-class-Groups_User_Group.html#84-132)
   as described here.
 * The link goes to Groups API which you are welcome to use for your own custom 
   implementations.
 * Kind regards,
    George

Viewing 1 replies (of 1 total)

The topic ‘do_shortcode groups_join not working in hook’ 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/)

 * 1 reply
 * 2 participants
 * Last reply from: [gtsiokos](https://wordpress.org/support/users/gtsiokos/)
 * Last activity: [7 years, 3 months ago](https://wordpress.org/support/topic/do_shortcode-groups_join-not-working-in-hook/#post-11222783)
 * Status: resolved