Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding Groups to Mailchimp Sync


  • elgroyconboy
    Participant

    @elgroyconboy

    Hello,

    I’m developing a website for my company and we’re trying to sync the assigned group data in buddy press with the user so when we go into mailchimp we can sort/partition our lists in mailchimp by the corresponding group.

    The code we’re using to sync all the other data in extended profile is here, but my concern is that we can’t pull the group the same way because it’s not something that gets added in the extended profile. I’m almost certain that I can’t pull the group with these parameters because when i look in the database, there’s no user-ID tied to any group. However, when i go into buddypress groups there’s users assigned to them.

    This is the function we’re using to sync:

    add_filter( ‘mailchimp_sync_user_data’, ‘mailchimp_buddypress’, 10, 2 );
    //Write the function
    function mailchimp_buddypress( $data, $user ) {

    //Get user ID
    $user_id = $user->ID;

    // Store Xprofile fields in the $data variable
    $data[‘JOBTITLE’] = xprofile_get_field_data( 11 , $user_id );
    $data[‘ORG’] = xprofile_get_field_data( 12 , $user_id );
    $data[‘CITY’] = xprofile_get_field_data( 36 , $user_id );
    $data[‘STATE’] = xprofile_get_field_data( 16 , $user_id );
    $data[‘COUNTRY’] = xprofile_get_field_data( 18 , $user_id );
    $data[‘PHONE’] = xprofile_get_field_data( 19 , $user_id );
    $data[‘SALUTATION’] = xprofile_get_field_data( 3 , $user_id );
    $data[‘GROUP’] = bp_get_current_group_id( 1 , $user_id );
    //Return the data
    return $data;

    }

    Right now the last line “$data[‘GROUP’] = bp_get_current_group_id( 1 , $user_id );” outputs a “0”.

    Thank you for reading! Hoping someone on here can help me.

Viewing 2 replies - 1 through 2 (of 2 total)

  • pmhn
    Participant

    @pmhn

    Hi,

    I don’t suppose you got anywhere with this? I’m looking for exactly the same thing but no joy.

    Many thanks,
    Chris.


    Peter Hardy-vanDoorn
    Participant

    @petervandoorn

    bp_get_current_group_id() gets the ID of the current group, not the groups to which the user is a member of.

    For that you need groups_get_user_groups().

    It will return an array of group info, so you’ll have to process it further before storing it.

    Have a look here: http://hookr.io/functions/groups_get_user_groups/

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar