My users have a relationship field called Organisation.
In my plugin, I am trying to fetch all users that are related to the organisation I pass it.
BUT I would like ALL users including Pending, so those who have not verified their email and set a password yet.
I am using this code but it only fetches the verified users, not pending.
$entries = craft\elements\User::find();
$relatedEntries = $entries->relatedTo(
array(
'targetElement' => $organisationId,
'field' => 'organisation'
)
);
// Fetch all entries
$relatedEntries = $relatedEntries->all();
I have also tried using combinations of ->status(null), e.g.
$entries = craft\elements\User::find();
$relatedEntries = $entries->relatedTo(
array(
'targetElement' => $organisationId,
'field' => 'organisation'
)
);
// Fetch all entries
$relatedEntries = $relatedEntries->status(null)->all();
or
$entries = craft\elements\User::find()->status(null);
$relatedEntries = $entries->relatedTo(
array(
'targetElement' => $organisationId,
'field' => 'organisation'
)
);
// Fetch all entries
$relatedEntries = $relatedEntries->all();
But they always just show all verified users.
Thanks
Edit
I have changed my logic and database setup a bit, and so decided to try using just template tags now. And so I got it working OK using .status(null with template tags.
{% set organisations = craft.entries().section('suppliers').authorId(currentUser.id) %}
{% for organisation in organisations %}
{% set users = craft.users().relatedTo(organisation).status(null %}
{% for user in users %}
{{user.firstName}} {{user.lastName}} - {{user.status}}<br/>
{% endfor%}
{% endfor%}