2

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.

2
  • Just curious, what's a significant amount of users? – Peter Tell Apr 14 '15 at 13:15
  • Not many actually, just over 200 in this case. – James Apr 14 '15 at 13:35
1

Does something like this work? You might need to add some wildcards as documented here to run the right kind of search.

$criteria = craft()->elements->getCriteria(ElementType::User);
$users = $criteria->search('customField: *' . $someValue.'*');
6
  • 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. – James Apr 14 '15 at 13:49
  • Hey James. Thanks for the clarification! Does the updated answer help? – Aaron Berkowitz Apr 14 '15 at 13:56
  • That doesn’t work unfortunately. Without the wildcard I’m getting some results just not all of them it seems. – James Apr 14 '15 at 15:02
  • 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? – Aaron Berkowitz Apr 14 '15 at 15:07
  • 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. – James Apr 14 '15 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.