Groups API question

Posted in

hello, sorry – wrong forum to post in but I can’t see where to post my question.

I am wanting to use Groups_User_Group::create for adding a user to a group. but can’t seem to get it to work.

For testing purposes I am using my test account with user id: ‘rjbwarren@tiscali.co.uk’ (I use email addresses as the login ID for accounts on my site)

and for testing purposes my group is called “SAGE” – Group id 2

I have set up the following:

$user_id=’rjbwarren@tiscali.co.uk’; ;
$group_id=’2′;

Groups_User_Group::create( array( ‘user_id’ => $user_id, ‘group_id’ => $group_id) );

However when I run it, it’s not adding the user to that group.

Am I missing a lot of other required configuration here, or is there just some mis-configuration?

I will, at some point enable a user to add themselves to multiple groups.

3 Responses to Groups API question

  1. Richard February 6, 2014 at 3:42 pm #

    Antonio,

    You are a star!!! thank you so much. I wasn’t miles off, but you have got be back on track.

    So grateful 🙂

    Rich

    • antonio February 7, 2014 at 7:03 am #

      perfect 😉

  2. antonio February 6, 2014 at 3:23 pm #

    Hi,
    “Groups_User_Group::create” needs user’s id. You can use for example:

    $user = get_user_by( 'email', 'rjbwarren@tiscali.co.uk' );
    if ($user) {
    $result = Groups_User_Group::create( array( "user_id"=>$user->ID, "group_id"=>2 ) );
    }

    cheers

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share