1

This works (but only obtains the active users):

// get entry
$entry = craft()->entries->getEntryById($entryId);

// get existing users in field
$entry->customUserField->ids();

So in attempting to get the non-active users I've switched to using the ElementCriteriaModel but have been unsuccessful:

// get entry
$entry = craft()->entries->getEntryById($entryId);

// get field model
$field = craft()->fields->getFieldByHandle('customUserField');

// get all users for entry+field
$getUsers = craft()->elements->getCriteria(ElementType::User);
$getUsers->relatedTo([
    'targetElement' => $entry,
    'field' => $field,
    'status' => null  // user status null
]);

$users = $getUsers->find();

I'm certain I'm doing something wrong within my relatedTo parameters. Help!

3

As always, spent hours trying to figure this out and came upon the answer within an hour after posting the question on Stack.

Here's the working code:

    // get entry
    $entry = craft()->entries->getEntryById($entryId);

    // get ALL users related to entry
    $users = craft()->elements->getCriteria(ElementType::User);
    $users->status = null;
    $users->relatedTo = [$entry];
    $userIds = $users->ids();

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.