<p>My assumption that the query was not getting all the related entries from withing the Matrix was wrong. The filtering that happens is applied at <em>output</em> level, and not the query level.</p>

<p>The solution is to tell craft that you don't care about the status of any linked anEntryField entry as part of the <code>if</code>...</p>

<pre><code>{% if
    user.myMatrixField | length
    and
    user.myMatrixField.first().anEntryField.status(null).first() | length
%}
...
{% endif %}
</code></pre>

<p>In this example the result will be the first myMatrixField block with a status of 'enabled' (that's the default filter), and fetching from that first Matrix result the first related Entry on the anEntryField regardless of the status of that related entry.</p>

<p>That's what I was after.</p>

CC BY-SA 4.0
2018-09-12T14:55:46.683Z
2018-09-12T14:55:46.683Z
Matt Wilcox
<p>I have a Matrix field on Users. In that Matrix field is an Entries field. I need to pull all Entries from that field, regardless of the related Entries status.</p>

<p>The following code returns Users but the Users' <code>anEntryField</code> only shows the default 'live' entries.</p>

<pre><code>{% set users = craft.users({
    with: [
        'myMatrixField:blockType.anEntryField'
    ]
}) %}
</code></pre>

<p>How do I pass status(null) to that field? Or, if it's actually getting all the Entries... how do I <em>show</em> them all?</p>

<p>I have tried:</p>

<pre><code>{% if
    user.myMatrixField | length
    and
    user.myMatrixField.first().anEntryField.first() | length
%} ... {% endif %}
</code></pre>

<p>But nothing in that block is executed for users who's anEntryField contains an entry that is disabled or expired.</p>

CC BY-SA 4.0
2018-09-12T14:29:23.873Z
It appears to work if I filter in the if statement. e.g., 4th line becomes `user.myMatrixField.first().anEntryField.status(null).first | length`
Matt Wilcox
<matrix><relations>
How to filter relational field types on their related content's status?
# How to filter relational field types on their related content's status?

(Asked by: username_0 on 2018-09-12)

I have a Matrix field on Users. In that Matrix field is an Entries field. I need to pull all Entries from that field, regardless of the related Entries status.
The following code returns Users but the Users' anEntryField only shows the default 'live' entries.
{% set users = craft.users({
    with: [
        'myMatrixField:blockType.anEntryField'
    ]
}) %}

How do I pass status(null) to that field? Or, if it's actually getting all the Entries... how do I show them all?
I have tried:
{% if
    user.myMatrixField | length
    and
    user.myMatrixField.first().anEntryField.first() | length
%} ... {% endif %}

But nothing in that block is executed for users who's anEntryField contains an entry that is disabled or expired.

**Tags:** matrix, relations

> **Comments:**
> **username_0**: It appears to work if I filter in the if statement. e.g., 4th line becomes `user.myMatrixField.first().anEntryField.status(null).first | length`  

---

## 1 answers

### Answer by username_0 on 2018-09-12. Score: 1 | Accepted answer

My assumption that the query was not getting all the related entries from withing the Matrix was wrong. The filtering that happens is applied at output level, and not the query level.
The solution is to tell craft that you don't care about the status of any linked anEntryField entry as part of the if...
{% if
    user.myMatrixField | length
    and
    user.myMatrixField.first().anEntryField.status(null).first() | length
%}
...
{% endif %}

In this example the result will be the first myMatrixField block with a status of 'enabled' (that's the default filter), and fetching from that first Matrix result the first related Entry on the anEntryField regardless of the status of that related entry.
That's what I was after.


---

