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: [
}) %}

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
    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.

  • 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 Sep 12 '18 at 14:29

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
    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.

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.