diff --git a/entityreference_prepopulate.module b/entityreference_prepopulate.module
index 65f3cc2..0075fb8 100755
--- a/entityreference_prepopulate.module
+++ b/entityreference_prepopulate.module
@@ -219,19 +219,46 @@ function entityreference_prepopulate_get_values($field, $instance, $flat_array =
 }
 
 function entityreference_prepopulate_get_values_from_og_context($field, $instance, $flat_array = FALSE) {
+  $cache = &drupal_static(__FUNCTION__, array());
   $field_name = $field['field_name'];
+  $identifier = $instance['entity_type'] . ':' . $instance['bundle'] . ':' . $field_name . ':' . $flat_array;
+  if (isset($cache[$identifier])) {
+    return $cache[$identifier];
+  }
 
-  if (!og_is_group_audience_field($field_name) || !$og_context = og_context()) {
+  if (!og_is_group_audience_field($field_name)) {
+    $cache[$identifier] = FALSE;
     return;
   }
 
-  if ($og_context['group_type'] != $field['settings']['target_type']) {
-    // Context is of invalid group-type.
-    return;
+  if ($og_context = og_context()) {
+    if ($og_context['group_type'] != $field['settings']['target_type']) {
+      // Context is of invalid group-type.
+      $cache[$identifier] = FALSE;
+      return;
+    }
+  }
+  else {
+    // Try to get the form out of cache.
+    $form_build_id = isset($_GET['form_build_id']) ? $_GET['form_build_id'] : isset($_POST['form_build_id']) ? $_POST['form_build_id'] : NULL;
+    $form_state = array();
+    $form = form_get_cache($form_build_id, $form_state);
+
+    // If successful, get the value from the form_state.
+    if (isset($form_state['entityreference_prepopulate'][$instance['entity_type']][$instance['bundle']][$field_name])) {
+      $ids = $form_state['entityreference_prepopulate'][$instance['entity_type']][$instance['bundle']][$field_name];
+      $og_context = array('gid' => $ids[0]['target_id']);
+    }
+    // If not, do nothing and return.
+    else {
+      $cache[$identifier] = FALSE;
+      return;
+    }
   }
 
   $items = array();
   $items[] = !$flat_array ? array('target_id' => $og_context['gid']) : $og_context['gid'];
+  $cache[$identifier] = $items;
   return $items;
 }
 
