I am trying to accomplish targeting but wondering if there is a way to combine these two? I took a look around and in the Craft 3 docs but I am a bit turned around on this, really would appreciate some help with it.

{% set parts = craft.categories.group('part').slug( urlSlug2 ) %}
{% set models = craft.categories.group('model').slug( urlSlug3 ) %}

{% set entries1 = craft.entries.section('flightcompany').relatedTo({
    targetElement: parts, 
    field: 'partsModels.part' 
}).limit(5).all() %}

{% set entries2 = craft.entries.section('flightcompany').relatedTo({
    targetElement: models, 
    field: 'partsModels.model' 
}).limit(5).all() %}

1 Answer 1


You might have seen Passing Multiple Relation Criteria in the docs

{% set entries = craft.entries.section('flightcompany').relatedTo([
    { targetElement: models, field: 'partsModels.model' },
    { targetElement: parts, field: 'partsModels.part' }
]).all() %}

You can as well take a look at the Db::parseParam the and|or syntax is the same for this field

  • Perfect! Thanks again Robin, you really have helped me out again :)
    – Vin
    Commented May 10, 2018 at 22:30
  • It seems I tried this and it came back with no results. I am trying to get the results between 2 matrix fields. Right now I am using conditionals and using .limit(25) and with the conditionals in the matrix loop I sometimes only get 4-5 results. So would be best to get them at the main entries loop.
    – Vin
    Commented May 12, 2018 at 19:21
  • Sorry but it's really difficult to understand your explanation. What do you want exactly? You won't fetch matrix blocks with your query. You'll receive elements of type entry. The code above works. I've used it many times without issues Commented May 12, 2018 at 19:38
  • I am sure it does, not working for me, it's me not you. I am trying to make sure that each of those conditions/data matches. So models = cessna and parts = front propeller in flightcompany limit 25 records. Those records exist in the extries but for some reason it works with just searching parts or models but not used together with 'and'.
    – Vin
    Commented May 12, 2018 at 21:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.