Initialize a new profile field for all users

Public

Snippet 279 didn't appear to contain profile fields, so this one should work for that purpose

</> CopyGet raw version
php
  1. /*
  2. * The following snippet will initialize a profile field for all user profiles. This is meant to
  3. * prepopulate a default value so that user without a value won't be excluded from view
  4. * and query results.
  5. */
  6.  
  7. $profiles = profile2_load_multiple(FALSE, array('type' =>'profile_type_name'));
  8. foreach($profiles as $profile) {
  9. profile->field_new_field_name[LANGUAGE_NONE][0]['value'] = 'the default value';
  10. profile2_save($profile);
  11. }