Having scoured the forums for similar questions of which there are a few, I'm still struggling to figure out my specific usecase. I have 4 filters and a search box (which searches a custom tag field) to filter craft.users in a group. 3 of the filters are matrix fields, 2 of the filters are posted as an array.
- Gender seems to be working fine:
- The first option’s gender value is empty “”, which seems to work and return both genders if selected. Is this fine, or should I be checking if a value has been posted? And if so, would I need to use a ternary operator to
seta default array for both male and female values?
- The first option’s gender value is empty “”, which seems to work and return both genders if selected. Is this fine, or should I be checking if a value has been posted? And if so, would I need to use a ternary operator to
- How do I add a Matrix field into the
craft.usersobject syntax?- Is this even possible? I can imagine setting something like
maxPrice: "<= #{maxPrice}"for a standard number field, but have no idea how I'd do so for a number field within a Matrix block:- i.e.
craft.users.profilePricing.type('details').session
- i.e.
- Is this even possible? I can imagine setting something like
I'm using matrix fields as they separate related chunks of data better, the specific ones I need to search are limited to number fields, dropdown and checkboxes. All of which only allow 1 block. For now at least, the filters should match all criteria with and logic.
Filters
Here is an example of the filter options:
<select name="gender">
<option value="">Male and female</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>
<div class="form-group">
<input id="maxPrice" type="number" name="maxPrice" min="0" max="100" step="5">
<label for="maxPrice"><small>Maximum session price</small></label>
</div>
<div class="form-group">
<label>
<input type="checkbox" value="skype" name="sessions[]" checked> Skype
</label>
<label>
<input type="checkbox" value="chat" name="sessions[]" checked> Live web chat
</label>
<label>
<input type="checkbox" value="phone" name="sessions[]" checked> Telephone
</label>
<label>
<input type="checkbox" value="email" name="sessions[]" checked> Email
</label>
</div>
<div class="form-group">
<label>
<input type="checkbox" value="office" name="hours[]" checked> Office hours
</label>
<label>
<input type="checkbox" value="overtime" name="hours[]" checked> Out of hours
</label>
<label>
<input type="checkbox" value="weekends" name="hours[]" checked> Weekends
</label>
</div>
Results
And the unfinished code for the search results:
<h1>Search Results</h1>
{% set tags = craft.request.getParam('tags') %}
{% set gender = craft.request.getParam('gender') %}
{% set maxPrice = craft.request.getParam('maxPrice') %}
{% set sessions = craft.request.getParam('sessions') %}
{% set hours = craft.request.getParam('hours') %}
{% set results = craft.users({
group: 'verified',
search: "tagsSpecialismSearchable:#{tags}",
gender: gender,
}) %}
{% set users = shuffle(results) %}
{% if users|length %}
<p>{{ users|length }} results:</p>
{% include '_includes/counsellors/profile.html' %}
{% else %}
<p>Your search for “{{ tags }}” didn’t return any results.</p>
{% endif %}
