So it seems that Matrix fields don't work with the object syntax so I've changed my field structure to use standard dropdowns, checkboxes and a number field.
I have the dropdown (gender) and number field (maxPrice) working fine, but I can't seem to figure out what to enter for the checkboxes. I assumed it'd be in a similar format to what I've seen elsewhere, as you can see below:
<h1>Search Results</h1>
{% set tags = craft.request.getParam('tags') %}
{# Gender is a dropdown, so it's a single value or no value
# - If an empty value is selected, it returns both genders #}
{% set gender = craft.request.getParam('gender') %}
{% set maxPrice = craft.request.getParam('maxPrice') %}
{% set maxPrice = maxPrice is not empty ? maxPrice : '99' %}
{% set sessions = craft.request.getParam('sessions') %}
{% set sessions = sessions is not empty ? sessions : ['skype', 'chat', 'phone', 'email'] %}
{% set sessions = ['and']|merge(sessions) %}
{% set hours = craft.request.getParam('hours') %}
{% set hours = hours is not empty ? hours : ['office', 'overtime', 'weekends'] %}
{% set hours = ['and']|merge(hours) %}
{% set results = craft.users({
group: 'verified',
search: "tagsSpecialismSearchable:#{tags}",
gender: gender,
profilePricingSession: [
'and',
'> 0',
"<= #{maxPrice}"
],
profileSessions: sessions,
profileHours: hours,
}) %}
{% set users = shuffle(results) %}
Everything works except profileSessions and profileHours, which are both checkboxes. I assumed it might be that they need to be passed a key: value pair, i.e: skype: true or some other method, but nothing I've tried so far is working.
I happened on a post saying checkboxes store in a query unfriendly way, so perhaps I'm better off changing the field again for something more friendly. They'd need to be multi-select of course, so categories would be the best bet if what I'm doing isn't possible.
Suggestions?
relatedTo? (it still confuses me a bit, especially when usingfield,sourceElementandtargetElement) – Rob Jan 16 '16 at 14:44relatedToparameter: Dynamic relatedTo queries (categories are most likely to be thetargetElement, as they are the elements selected in the field and not the element the field is attachted to). – carlcs Jan 16 '16 at 15:02dropdown: 'value'or would it be something likefield: trueorfield: '0'? Craft is brilliant but these little intricacies can take some getting used to — hopefully the v3 api will give us more options :) – Rob Jan 16 '16 at 15:08for loopthrough all thequery[]=group arrays? I don't think I fully understand what your example is doing. – Rob Jan 19 '16 at 21:46query.artparameter array into.id()and merging each with it's own{ targetElement: categoryName }, but I thought.id()and.slugcould only take one string at a time. Is it something similar to the second example in Twig docs which (due to being wrapped in[]creates a list ofkey: valuepairs? Or am I off the mark? I come from a front-end background so this stuff makes my head hurt! – Rob Jan 19 '16 at 22:01