Drupal 7 load profile2 programmatically

sisko picture sisko · Mar 3, 2012 · Viewed 9.5k times · Source

I have two profile2 profiles defined - main and customer_profile. Also, I have a node type called Customer.

When creating a new Customer node, I would like to load the custom_profile form. The idea is to create a node and a profile simultaneously.

I know it's definately a hook_form_alter solution but can someone tell me how to programmatically load a profile while creating or editing a Customer node.

Answer

Nitesh Agarwal picture Nitesh Agarwal · Jan 11, 2013

You can load profile type and data by using these function

$types = profile2_get_types();
profile2_load_by_user($account, $type_name = NULL)

For Example :

$types = profile2_get_types();
    if (!empty($types)) {
        foreach ($types as $type) {
            $profile = profile2_load_by_user($uid, $type->type);
        }
    }