Answers.Body: <p>Join on contact user accounts and add the cms id to the columns.</p>
  <p><a href="https://i.sstatic.net/H4ayb0Oy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/H4ayb0Oy.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-19T04:42:44.443Z
Answers.Text: I'm trying to get the CMS ID for everybody in a search result (or Null/empty if they have none), not limit to only people with a CMS ID.
Answers.UserDisplayName: Ken Williams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-19T04:48:35.347Z
Answers.Text: Oops, sorry, I see that this works quite well for my use case, I missed the "(optional)" part of that query.  Thanks!
Answers.UserDisplayName: Ken Williams
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-09-19T04:10:47.377Z
Answers.LastActivityDate: 2024-09-19T04:10:47.377Z
Answers.UserDisplayName: Demerit
Body: <p>Is there a way for search results to show the WordPress user ID for each user?  I can't seem to find a way to include it in SearchKit results, or in export-to-csv fields, or in Search Builder, etc.  The only way I've found is to use raw SQL:</p>
  <pre><code>SELECT c.id, c.display_name, um.uf_id
  FROM civicrm_contact c LEFT JOIN civicrm_uf_match um ON c.id=um.contact_id
  WHERE c.id IN (
      SELECT contact_id
      FROM civicrm_group_contact
      WHERE group_id IN (
          SELECT id
          FROM civicrm_group
          WHERE name='The Group Name'
      )
      AND status='Added'
  );
  </code></pre>
  <p>I'm using CiviCRM 5.76.2 on WordPress 6.6.2 (self-hosted).</p>
  
Tags: <wordpress><search><searchkit><user-account>
Title: Query for WordPress user ID
ThreadText: # Query for WordPress user ID
  
  (Asked by: username_0 on 2024-09-19)
  
  Is there a way for search results to show the WordPress user ID for each user?  I can't seem to find a way to include it in SearchKit results, or in export-to-csv fields, or in Search Builder, etc.  The only way I've found is to use raw SQL:
  SELECT c.id, c.display_name, um.uf_id
  FROM civicrm_contact c LEFT JOIN civicrm_uf_match um ON c.id=um.contact_id
  WHERE c.id IN (
      SELECT contact_id
      FROM civicrm_group_contact
      WHERE group_id IN (
          SELECT id
          FROM civicrm_group
          WHERE name='The Group Name'
      )
      AND status='Added'
  );
  
  I'm using CiviCRM 5.76.2 on WordPress 6.6.2 (self-hosted).
  
  **Tags:** wordpress, search, searchkit, user-account
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-09-19. Score: 4 | Accepted answer
  
  Join on contact user accounts and add the cms id to the columns.
  
  [![enter image description here](https://i.sstatic.net/H4ayb0Oy.png)](https://i.sstatic.net/H4ayb0Oy.png)
  
  > **Comments:**
  > **username_0**: I'm trying to get the CMS ID for everybody in a search result (or Null/empty if they have none), not limit to only people with a CMS ID.  
  > **username_0**: Oops, sorry, I see that this works quite well for my use case, I missed the "(optional)" part of that query.  Thanks!  
  
  ---
  
  