Skip to content

andRelatedTo with a condition #15886

Answered by brandonkelly
shifuma asked this question in Q&A
Discussion options

You must be logged in to vote

Gotcha. The only current way to do that is by getting the IDs of the nested entries first, and then passing them to the Matrix field’s param on the parent entry query:

{% set nestedIds = craft.entries()
  .field('myMatrixField')
  .type(['type1Handle', 'type3Handle'])
  .ids() %}

{% if nestedIds|length %}
  {% set entries = craft.entries()
    .section('mySection')
    .myMatrixField(nestedIds)
    .all() %}
{% endif %}

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@shifuma
Comment options

@brandonkelly
Comment options

Answer selected by brandonkelly
@shifuma
Comment options

@brandonkelly
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants