I'm not able to query a list of items relatet to a category or if category field is empty in the same query. I have to make two and merge them.

Is it not possible?

This works:

{# Fetch entries related to the specified category #}
{% set relatedDetails = plan.policyDetails
                              .relatedTo({ targetElement: block.category.one(), field: 'category' })
                              .all() %}
{# Fetch entries without any category assigned #}
{% set unassignedDetails = plan.policyDetails.category(':empty:').all()%}
{# Combine the two sets of entries #}
{% set customDetails = relatedDetails|merge(unassignedDetails)|unique %}

This does not work (does not include entries that has empty category field):

{% set customDetails = plan.policyDetails
        { targetElement: block.category.one(), field: 'category' },
        { targetElement: ':empty:', field: 'category' } // Check for empty category
    .all() %}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.