Answers.Body: <p>Apologies if I’ve misunderstood your question and over-simplified things, but wouldn’t the search() method give you precisely what you need?</p>
  <p>As in:</p>
  <pre><code>{% set valsToFind = &quot;field_photoColor:red OR field_photoColor:green OR field_photoSubject:animal OR field_photoSize:small&quot; %}
  {% set galleries = craft.entries.section(&quot;gallery&quot;).search(valsToFind).all() %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-24T23:36:33.353Z
Answers.Text: Unfortunately, that doesn't return any results. Even if I simplify it to just one field, i.e. {% set galleries = craft.entries.section("gallery").search("field_photoColor:red") %} there still aren't any results.
Answers.UserDisplayName: Jake1293
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-25T00:02:02.473Z
Answers.Text: Try just "red" as in {% set galleries = craft.entries.section("gallery").search("red").all() %}
Answers.UserDisplayName: mitrol
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-25T00:17:19.487Z
Answers.Text: That was it, I needed to structure the query like this:  {% set galleries = craft.entries.section("gallery").search("red OR green OR animal OR large").  Thank you so much! I've been stuck on this for days.
Answers.UserDisplayName: Jake1293
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-25T13:40:32.250Z
Answers.Text: Awesome, glad it worked.
  
  Looking at the code in the light of day, the field names are probably wrong.
  {% set galleries = craft.entries.section("gallery").search("photoColor:red") %}
  should also work.
  
  Cheers.
Answers.UserDisplayName: mitrol
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-24T23:16:21.543Z
Answers.LastActivityDate: 2020-06-24T23:16:21.543Z
Answers.UserDisplayName: mitrol
Answers.Body: <p>I think this will get you there.</p>
  <pre><code>{% set galleries = craft.entries
      .section(&quot;gallery&quot;)
      .where([
          'or',
          {'field_photoColor'   : 'red' },
          {'field_photoColor'   : 'green' },
          {'field_photoSubject' : 'animal' },
          {'field_photoSize'    : 'small' }
      ])
  %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-24T13:01:13.103Z
Answers.Text: Unfortunately, it's not returning any results. I tried with an easy example using only one field, photoColor.
Answers.UserDisplayName: Jake1293
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-24T16:33:49.437Z
Answers.Text: Then it's likely you have a misnamed field or typo some where in your implementation, because that code queries data from entries in exactly the way you're looking for.
Answers.UserDisplayName: stevecomrie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-24T17:59:05.057Z
Answers.Text: Hmmm...I'm not sure what I'm doing wrong. I double checked all the handles, they're all correct.
Answers.UserDisplayName: Jake1293
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-24T05:58:12.353Z
Answers.LastActivityDate: 2020-06-24T05:58:12.353Z
Answers.UserDisplayName: stevecomrie
Body: <p>I've set up checkbox fields for photos in a photo gallery called &quot;photoColor&quot;, &quot;photoSubject&quot;, and &quot;photoSize&quot;, all of which contain a bunch of options.</p>
  <p>On the gallery page I have filters and I'm using Ajax to update the page when a checkbox is clicked.</p>
  <pre><code>&lt;div id=&quot;filters&quot;&gt;
   &lt;input type=&quot;checkbox&quot; name=&quot;colors[]&quot; value=&quot;red&quot; /&gt; Red
   &lt;input type=&quot;checkbox&quot; name=&quot;colors[]&quot; value=&quot;green&quot; /&gt; Green
  
   &lt;input type=&quot;checkbox&quot; name=&quot;subjects[]&quot; value=&quot;human&quot; /&gt; Human
   &lt;input type=&quot;checkbox&quot; name=&quot;subjects[]&quot; value=&quot;animal&quot; /&gt; Animal
  
   &lt;input type=&quot;checkbox&quot; name=&quot;sizes[]&quot; value=&quot;small&quot; /&gt; Small
   &lt;input type=&quot;checkbox&quot; name=&quot;sizes[]&quot; value=&quot;large&quot; /&gt; Large
  &lt;/div&gt;
  </code></pre>
  <p>I'm gathering the values of the checkboxes like this</p>
  <pre><code>  var colors = [], subjects = [], sizes = [];
    $('input[name=&quot;colors[]&quot;]:checked').each(function() {
       colors.push($(this).val());
    });
  
    $('input[name=&quot;subjects[]&quot;]:checked').each(function() {
       subjects.push($(this).val());
    });
  
    $('input[name=&quot;sizes[]&quot;]:checked').each(function() {
       sizes.push($(this).val());
    });
  </code></pre>
  <p>Right now I can filter for one option of one field type, i.e. this works:</p>
  <pre><code>{%  set galleries = craft.entries.section(&quot;gallery&quot;).photoColor(value) %}
  </code></pre>
  <p>(where value = &quot;red&quot; for example)</p>
  <p>But I'm struggling to figure out how to write the query to combine ALL 3 field types in an &quot;or&quot; query, i.e. the results only need to match one of those properties, not all of them.</p>
  <p>In other words, if a user checks off red, green, animal, and small, it will show all the results matching either red, green, animal, OR small - not just red/green animals that are small.</p>
  <p>In pseudo code, it would be something like:</p>
  <pre><code>{% set galleries = craft.entries.section(&quot;gallery&quot;)
    where .photoColor is red or green
     or .photoSubject is animal
     or .photoSize is small
  %}
  </code></pre>
  <p>I've been searching StackExchange and trying things I saw in other answers for days, but none of the situations were quite like mine, so I haven't been able to get it to work. Can someone point me in the right direction? Any help is greatly appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-24T09:14:48.450Z
Comments.Text: Are the 'colours', 'subjects' and 'sizes' categories in Craft?
Comments.UserDisplayName: dmatthams
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-06-24T12:55:39.673Z
Comments.Text: No, they are just set up as checkbox fields. I haven't used the category field type yet. I just looked at it. I'm not sure how to add all the values like I did with the checkbox fields. I"ll have to look into the documentation on that.
Comments.UserDisplayName: Jake1293
Tags: <filter><checkboxes>
Title: How to filter entries by multiple checkbox field types
ThreadText: # How to filter entries by multiple checkbox field types
  
  (Asked by: username_0 on 2020-06-24)
  
  I've set up checkbox fields for photos in a photo gallery called "photoColor", "photoSubject", and "photoSize", all of which contain a bunch of options.
  
  On the gallery page I have filters and I'm using Ajax to update the page when a checkbox is clicked.
  
  ```
  <div id="filters">
   <input type="checkbox" name="colors[]" value="red" /> Red
   <input type="checkbox" name="colors[]" value="green" /> Green
  
   <input type="checkbox" name="subjects[]" value="human" /> Human
   <input type="checkbox" name="subjects[]" value="animal" /> Animal
  
   <input type="checkbox" name="sizes[]" value="small" /> Small
   <input type="checkbox" name="sizes[]" value="large" /> Large
  </div>
  
  ```
  
  I'm gathering the values of the checkboxes like this
  
  ```
    var colors = [], subjects = [], sizes = [];
    $('input[name="colors[]"]:checked').each(function() {
       colors.push($(this).val());
    });
  
    $('input[name="subjects[]"]:checked').each(function() {
       subjects.push($(this).val());
    });
  
    $('input[name="sizes[]"]:checked').each(function() {
       sizes.push($(this).val());
    });
  
  ```
  
  Right now I can filter for one option of one field type, i.e. this works:
  
  ```
  {%  set galleries = craft.entries.section("gallery").photoColor(value) %}
  
  ```
  
  (where value = "red" for example)
  
  But I'm struggling to figure out how to write the query to combine ALL 3 field types in an "or" query, i.e. the results only need to match one of those properties, not all of them.
  
  In other words, if a user checks off red, green, animal, and small, it will show all the results matching either red, green, animal, OR small - not just red/green animals that are small.
  
  In pseudo code, it would be something like:
  
  ```
  {% set galleries = craft.entries.section("gallery")
    where .photoColor is red or green
     or .photoSubject is animal
     or .photoSize is small
  %}
  
  ```
  
  I've been searching StackExchange and trying things I saw in other answers for days, but none of the situations were quite like mine, so I haven't been able to get it to work. Can someone point me in the right direction? Any help is greatly appreciated.
  
  **Tags:** filter, checkboxes
  
  > **Comments:**
  > **username_1**: Are the 'colours', 'subjects' and 'sizes' categories in Craft?  
  > **username_0**: No, they are just set up as checkbox fields. I haven't used the category field type yet. I just looked at it. I'm not sure how to add all the values like I did with the checkbox fields. I"ll have to look into the documentation on that.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-06-24. Score: 2 | Accepted answer
  
  Apologies if I’ve misunderstood your question and over-simplified things, but wouldn’t the search() method give you precisely what you need?
  
  As in:
  
  ```
  {% set valsToFind = "field_photoColor:red OR field_photoColor:green OR field_photoSubject:animal OR field_photoSize:small" %}
  {% set galleries = craft.entries.section("gallery").search(valsToFind).all() %}
  
  ```
  
  > **Comments:**
  > **username_0**: Unfortunately, that doesn't return any results. Even if I simplify it to just one field, i.e. {% set galleries = craft.entries.section("gallery").search("field_photoColor:red") %} there still aren't any results.  
  > **username_2**: Try just "red" as in {% set galleries = craft.entries.section("gallery").search("red").all() %}  
  > **username_0**: That was it, I needed to structure the query like this:  {% set galleries = craft.entries.section("gallery").search("red OR green OR animal OR large").  Thank you so much! I've been stuck on this for days.  
  > **username_2**: Awesome, glad it worked.  Looking at the code in the light of day, the field names are probably wrong. {% set galleries = craft.entries.section("gallery").search("photoColor:red") %} should also work.  Cheers.  
  
  ---
  
  ### Answer by username_3 on 2020-06-24. Score: 1
  
  I think this will get you there.
  
  ```
  {% set galleries = craft.entries
      .section("gallery")
      .where([
          'or',
          {'field_photoColor'   : 'red' },
          {'field_photoColor'   : 'green' },
          {'field_photoSubject' : 'animal' },
          {'field_photoSize'    : 'small' }
      ])
  %}
  
  ```
  
  > **Comments:**
  > **username_0**: Unfortunately, it's not returning any results. I tried with an easy example using only one field, photoColor.  
  > **username_3**: Then it's likely you have a misnamed field or typo some where in your implementation, because that code queries data from entries in exactly the way you're looking for.  
  > **username_0**: Hmmm...I'm not sure what I'm doing wrong. I double checked all the handles, they're all correct.  
  
  ---
  
  