Answers.Body: <p>Does something like this work? You might need to add some wildcards as <a href="http://buildwithcraft.com/docs/searching" rel="nofollow">documented here</a> to run the right kind of search.</p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
  $users = $criteria-&gt;search('customField: *' . $someValue.'*');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T13:49:11.817Z
Answers.Text: Thanks Aaron. I should have mentioned that I’m using search as I need to find a value within that field in this case. Field is typically 1,2,3 and I need to check for on of those values.
Answers.UserDisplayName: James
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T13:56:02.517Z
Answers.Text: Hey James. Thanks for the clarification! Does the updated answer help?
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T15:02:02.483Z
Answers.Text: That doesn’t work unfortunately. Without the wildcard I’m getting some results just not all of them it seems.
Answers.UserDisplayName: James
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T15:07:26.130Z
Answers.Text: Hmm ok. Can you provide some details about the field? Is it a plain text field? What kind of values are typically stored and what kind of example values are you searching for?
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T15:57:29.387Z
Answers.Text: I am actually looking for a number value in a string. So, literally $someValue = 1 and the user custom field is plain text with 1,2,3. I’ve just realised the users that get missed are those that had those fields populated by another plugin. This looks as though the data is not being saved in the same way as when it’s entered manually in the CP.
Answers.UserDisplayName: James
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T16:02:45.580Z
Answers.Text: Yep, existing fields that contain 1,2,3 are not returned. When I replace this in the CP manually with the same 1,2,3, they show up.
Answers.UserDisplayName: James
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T13:45:14.343Z
Answers.LastActivityDate: 2015-04-14T13:55:55.427Z
Answers.LastEditDate: 2015-04-14T13:55:55.427Z
Answers.UserDisplayName: Aaron Berkowitz
Body: <p>This did work until there’s a significant amount of users: </p>
  
  <pre><code>$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
  $users = $criteria-&gt;search('customField:' . $someValue);
  </code></pre>
  
  <p>I’m using search as I need to find a value within the custom field. The field is typically 1,2,3 and I need to check for one of those values.</p>
  
  <p>I have also tried to limit it without success.</p>
  
  <pre><code>$criteria-&gt;groupId = 1;
  $criteria-&gt;limit = null;
  </code></pre>
  
  <p>What’s the best way to do this?</p>
  
  <p>UPDATE:</p>
  
  <p>The users getting missed are those that had the fields I’m searching populated by another plugin. This looks as though the data is not being saved in the same way as when it’s entered manually in the CP.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-14T13:15:24.800Z
Comments.Text: Just curious, what's a significant amount of users?
Comments.UserDisplayName: Peter Tell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-14T13:35:18.437Z
Comments.Text: Not many actually, just over 200 in this case.
Comments.UserDisplayName: James
Tags: <plugin-development><users><elementcriteriamodel>
Title: Best way to search users by a custom field inside a plugin?
ThreadText: # Best way to search users by a custom field inside a plugin?
  
  (Asked by: username_0 on 2015-04-14)
  
  This did work until there’s a significant amount of users:
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::User);
  $users = $criteria->search('customField:' . $someValue);
  
  ```
  
  I’m using search as I need to find a value within the custom field. The field is typically 1,2,3 and I need to check for one of those values.
  
  I have also tried to limit it without success.
  
  ```
  $criteria->groupId = 1;
  $criteria->limit = null;
  
  ```
  
  What’s the best way to do this?
  
  UPDATE:
  
  The users getting missed are those that had the fields I’m searching populated by another plugin. This looks as though the data is not being saved in the same way as when it’s entered manually in the CP.
  
  **Tags:** plugin-development, users, elementcriteriamodel
  
  > **Comments:**
  > **username_1**: Just curious, what's a significant amount of users?  
  > **username_0**: Not many actually, just over 200 in this case.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-04-14. Score: 1
  
  Does something like this work? You might need to add some wildcards as [documented here](http://buildwithcraft.com/docs/searching) to run the right kind of search.
  
  ```
  $criteria = craft()->elements->getCriteria(ElementType::User);
  $users = $criteria->search('customField: *' . $someValue.'*');
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_2. I should have mentioned that I’m using search as I need to find a value within that field in this case. Field is typically 1,2,3 and I need to check for on of those values.  
  > **username_2**: Hey username_0. Thanks for the clarification! Does the updated answer help?  
  > **username_0**: That doesn’t work unfortunately. Without the wildcard I’m getting some results just not all of them it seems.  
  > **username_2**: Hmm ok. Can you provide some details about the field? Is it a plain text field? What kind of values are typically stored and what kind of example values are you searching for?  
  > **username_0**: I am actually looking for a number value in a string. So, literally $someValue = 1 and the user custom field is plain text with 1,2,3. I’ve just realised the users that get missed are those that had those fields populated by another plugin. This looks as though the data is not being saved in the same way as when it’s entered manually in the CP.  
  > **username_0**: Yep, existing fields that contain 1,2,3 are not returned. When I replace this in the CP manually with the same 1,2,3, they show up.  
  
  ---
  
  