Searching for users from a plugin
Find a single user by his/her affiliateId (int).


$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
$criteria-&gt;affiliateId = 1;
$users = $criteria-&gt;find();



  Query all users within the Affiliate group, order by studentCount asc and return the top record. (I need a user that has the fewest number of students).


$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);
$criteria-&gt;affiliateGroup = 'myGroup';
$criteria-&gt;order = 'studentCount ASC';
$criteria-&gt;limit = 1;
$users = $criteria-&gt;find();