Answers.Body: <p>I would use api to find groups of logged in user</p>
  
  <pre><code>$result = civicrm_api3('Contact', 'getsingle', [
    'return' =&gt; ["group"],
    'id' =&gt; 'user_contact_id',
  ]);
  
  or 
  
  $result = civicrm_api3('GroupContact', 'getsingle', [
    'return' =&gt; ["group_id"],
    'contact_id' =&gt; 'user_contact_id',
  ]);
  </code></pre>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-08T10:24:07.557Z
Answers.LastActivityDate: 2019-01-08T10:24:07.557Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I am trying to get a group id of currently logged in user </p>
  
  <p><code>
  function search_civicrm_preProcess($formName, &amp;$form) {
      $getContactId = (int) CRM_Core_Session::singleton()-&gt;getLoggedInContactID();
      $query = "select 'group_id' from 'civicrm_group_contact' where contact_id ='.$getContactId'";
  $dao1 =&amp;  CRM_Core_DAO::executeQuery( $query, CRM_Core_DAO::$_nullArray );<br>
  }</code></p>
  
Tags: <extension><groups><core>
Title: Getting problem while getting group id of current logged in user
ThreadText: # Getting problem while getting group id of current logged in user
  
  (Asked by: username_0 on 2019-01-08)
  
  I am trying to get a group id of currently logged in user
  
  `function search_civicrm_preProcess($formName, &$form) {
  $getContactId = (int) CRM_Core_Session::singleton()->getLoggedInContactID();
  $query = "select 'group_id' from 'civicrm_group_contact' where contact_id ='.$getContactId'";
  $dao1 =& CRM_Core_DAO::executeQuery( $query, CRM_Core_DAO::$_nullArray );  
  }`
  
  **Tags:** extension, groups, core
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-08. Score: 1
  
  I would use api to find groups of logged in user
  
  ```
  $result = civicrm_api3('Contact', 'getsingle', [
    'return' => ["group"],
    'id' => 'user_contact_id',
  ]);
  
  or 
  
  $result = civicrm_api3('GroupContact', 'getsingle', [
    'return' => ["group_id"],
    'contact_id' => 'user_contact_id',
  ]);
  
  ```
  
  HTH
  
  username_1
  
  
  ---
  
  