Answers.Body: <p>Ok, I was close :P</p>
  
  <p>The trick is to create an object to pass instead of an array. The documentation for this is sketchy and confusing so I hope this snippet helps someone.</p>
  
  <p>Notice I am setting 'and' at the root of the object, but this only applies to the objects that follow, not to targetElement arrays. So by separating all the features into separate objects, the 'and' is applied to them, but not the models.</p>
  
  <pre><code>{% set models = [24, 25, 26] %}
  {% set features = [46, 47, 48] %}
  
  {%
    set relatedTo = ['and', {
      targetElement: models,
      field: 'model'
    }]
  %}
  
  {% for feature in features %}
    {% set relatedTo = relatedTo|merge([{
      targetElement: feature,
      field: 'feature'
    }]) %}
  {% endfor %}
  
  {%
    set entries = craft.entries({
      relatedTo: relatedTo
    })
  %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-11T15:33:57.107Z
Answers.LastActivityDate: 2015-03-11T15:33:57.107Z
Answers.UserDisplayName: Jake Cattrall
Body: <p>I have 2 categories, model and feature which I've added as a field to an entry. I want to find entries with the model category using "or" but the feature category using "and". I believe the "relatedTo" functionality only allows one kind which is very restrictive.</p>
  
  <pre><code>{% set model = [24, 25, 26] %}
  {% set feature = ['AND', 46, 47, 48] %}
  
  {%
      set entries = craft.entries({
          relatedTo: [model, feature]
      })
  %}
  </code></pre>
  
  <p>The code above is an example, but it returns no results.
  How else can I achieve this?</p>
  
Tags: <entries><relations>
Title: Find entries with multiple categories with an and/or twist
ThreadText: # Find entries with multiple categories with an and/or twist
  
  (Asked by: username_0 on 2015-03-11)
  
  I have 2 categories, model and feature which I've added as a field to an entry. I want to find entries with the model category using "or" but the feature category using "and". I believe the "relatedTo" functionality only allows one kind which is very restrictive.
  
  ```
  {% set model = [24, 25, 26] %}
  {% set feature = ['AND', 46, 47, 48] %}
  
  {%
      set entries = craft.entries({
          relatedTo: [model, feature]
      })
  %}
  
  ```
  
  The code above is an example, but it returns no results.
  How else can I achieve this?
  
  **Tags:** entries, relations
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-03-11. Score: 1
  
  Ok, I was close :P
  
  The trick is to create an object to pass instead of an array. The documentation for this is sketchy and confusing so I hope this snippet helps someone.
  
  Notice I am setting 'and' at the root of the object, but this only applies to the objects that follow, not to targetElement arrays. So by separating all the features into separate objects, the 'and' is applied to them, but not the models.
  
  ```
  {% set models = [24, 25, 26] %}
  {% set features = [46, 47, 48] %}
  
  {%
    set relatedTo = ['and', {
      targetElement: models,
      field: 'model'
    }]
  %}
  
  {% for feature in features %}
    {% set relatedTo = relatedTo|merge([{
      targetElement: feature,
      field: 'feature'
    }]) %}
  {% endfor %}
  
  {%
    set entries = craft.entries({
      relatedTo: relatedTo
    })
  %}
  
  ```
  
  
  ---
  
  