Answers.Body: <p>In your own cron job you could reload the cache for groups by calling civicrm_api3_job_group_rebuild() (<a href="https://github.com/civicrm/civicrm-core/blob/master/api/v3/Job.php#L629" rel="nofollow">https://github.com/civicrm/civicrm-core/blob/master/api/v3/Job.php#L629</a>), then cycle through the group to fill your custom field.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-03T20:19:31.850Z
Answers.Text: Brilliant, Joe.  This work is scheduled for a couple of weeks from now, I'll mark it accepted assuming this works!
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-02T17:00:44.017Z
Answers.LastActivityDate: 2015-12-02T17:00:44.017Z
Answers.UserDisplayName: Joe Murray
Body: <p>I want to generate membership cards based on a person's geographical region.  The region logic is fairly complex (e.g. "Anyone in NY, plus New Jersey north of Trenton and Connecticut west of Stamford").  I have smart groups that accurately place someone by region.</p>
  
  <p>Before we used smart groups, we manually added folks to static groups based on region. An extension called <code>civicrm_post</code> on the GroupContact to set the custom field.  However, <code>civicrm_post</code> isn't called on smart groups.</p>
  
  <p>Does anyone have any ideas?  I don't mind using SQL in a cron job, but I'm not sure that <code>civicrm_group_contact_cache</code> is reliably filled with the correct data - in older versions of Civi at least, I often found it empty.</p>
  
  <p>This is Civi 4.6.10, Wordpress.</p>
  
Tags: <hooks><developer><smartgroups>
Title: How can I set a custom field based on membership in a smart group?
ThreadText: # How can I set a custom field based on membership in a smart group?
  
  (Asked by: username_0 on 2015-11-25)
  
  I want to generate membership cards based on a person's geographical region. The region logic is fairly complex (e.g. "Anyone in NY, plus New Jersey north of Trenton and Connecticut west of Stamford"). I have smart groups that accurately place someone by region.
  
  Before we used smart groups, we manually added folks to static groups based on region. An extension called `civicrm_post` on the GroupContact to set the custom field. However, `civicrm_post` isn't called on smart groups.
  
  Does anyone have any ideas? I don't mind using SQL in a cron job, but I'm not sure that `civicrm_group_contact_cache` is reliably filled with the correct data - in older versions of Civi at least, I often found it empty.
  
  This is Civi 4.6.10, Wordpress.
  
  **Tags:** hooks, developer, smartgroups
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-12-02. Score: 1
  
  In your own cron job you could reload the cache for groups by calling civicrm\_api3\_job\_group\_rebuild() (<https://github.com/civicrm/civicrm-core/blob/master/api/v3/Job.php#L629>), then cycle through the group to fill your custom field.
  
  > **Comments:**
  > **username_0**: Brilliant, Joe.  This work is scheduled for a couple of weeks from now, I'll mark it accepted assuming this works!  
  
  ---
  
  