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
    Commented Apr 14, 2015 at 13:15
  • Not many actually, just over 200 in this case.
    – James
    Commented Apr 14, 2015 at 13:35

1 Answer 1

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
    Commented Apr 14, 2015 at 13:49
  • Hey James. Thanks for the clarification! Does the updated answer help? Commented Apr 14, 2015 at 13:56
  • That doesn’t work unfortunately. Without the wildcard I’m getting some results just not all of them it seems.
    – James
    Commented Apr 14, 2015 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? Commented Apr 14, 2015 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
    Commented Apr 14, 2015 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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