diff --git a/commons_groups.module b/commons_groups.module
index 4624f1d..ce10267 100644
--- a/commons_groups.module
+++ b/commons_groups.module
@@ -6,6 +6,14 @@
 
 include_once 'commons_groups.features.inc';
 
+/**
+ * Implements hook_ctools_plugin_directory().
+ */
+function commons_groups_ctools_plugin_directory($module, $plugin) {
+  if ($module == 'entityreference') {
+    return "plugins/entityreference/$plugin";
+  }
+}
 
 /**
  * Implements hook_entity_view().
diff --git a/plugins/entityreference/selection/OgCommonsGroupsSelectionHandler.class.php b/plugins/entityreference/selection/OgCommonsGroupsSelectionHandler.class.php
new file mode 100644
index 0000000..c652495
--- /dev/null
+++ b/plugins/entityreference/selection/OgCommonsGroupsSelectionHandler.class.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * @file
+ * OG Commons groups selection handler.
+ */
+
+class OgCommonsGroupsSelectionHandler extends OgSelectionHandler {
+
+  public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
+    return new self($field, $instance, $entity_type, $entity);
+  }
+
+  /**
+   * Overrides OgSelectionHandler::buildEntityFieldQuery().
+   */
+  public function buildEntityFieldQuery($match = NULL, $match_operator = 'CONTAINS') {
+    $group_type = $this->field['settings']['target_type'];
+
+    if (empty($this->instance['field_mode']) || $group_type != 'node') {
+      return parent::buildEntityFieldQuery($match, $match_operator);
+    }
+
+    $handler = EntityReference_SelectionHandler_Generic::getInstance($this->field, $this->instance, $this->entity_type, $this->entity);
+    $query = $handler->buildEntityFieldQuery($match, $match_operator);
+
+    // Show only the entities that are active groups.
+    $query->fieldCondition(OG_GROUP_FIELD, 'value', 1);
+
+    $query->fieldCondition('field_privacy_settings', 'value', 'public');
+    $gids = og_get_entity_groups();
+    if (!empty($gids['node'])) {
+      $query->propertyCondition('nid', $gids['node'], 'IN');
+    }
+
+    $query->addMetaData('entityreference_selection_handler', $this);
+
+    // FIXME: http://drupal.org/node/1325628
+    unset($query->tags['node_access']);
+
+    $query->addTag('entity_field_access');
+    $query->addTag('og');
+
+    return $query;
+  }
+
+  public function entityFieldQueryAlter(SelectQueryInterface $query) {
+//    $query->leftJoin('field_data_field_privacy_settings', 'fpa', "node.nid = fpa.entity_id && fpa.entity_type = 'node'");
+  }
+
+}
+
+
+
diff --git a/plugins/entityreference/selection/og_commons_groups.inc b/plugins/entityreference/selection/og_commons_groups.inc
new file mode 100644
index 0000000..eba3990
--- /dev/null
+++ b/plugins/entityreference/selection/og_commons_groups.inc
@@ -0,0 +1,6 @@
+<?php
+
+$plugin = array(
+  'title' => t('Commons groups OG'),
+  'class' => 'OgCommonsGroupsSelectionHandler',
+);
