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.

  1. 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 set a default array for both male and female values?
  2. How do I add a Matrix field into the craft.users object 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'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.


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>
<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 class="form-group">
    <input type="checkbox" value="skype" name="sessions[]" checked> Skype
    <input type="checkbox" value="chat" name="sessions[]" checked> Live web chat
    <input type="checkbox" value="phone" name="sessions[]" checked> Telephone
    <input type="checkbox" value="email" name="sessions[]" checked> Email
<div class="form-group">
    <input type="checkbox" value="office" name="hours[]" checked> Office hours
    <input type="checkbox" value="overtime" name="hours[]" checked> Out of hours
    <input type="checkbox" value="weekends" name="hours[]" checked> Weekends


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 %}

Search filters


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.