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.