0

I have four category groups (Position, State, Status, Denomination). I am trying to create a search form so all four categories can be utilized together or individually.

Here is what I have for my form:

<form action="{{ url('ministry-jobs/results') }}">

<input type="search" name="query" placeholder="What are you looking for?" style="width: 100%;">

<select name="position[]">
  <option value="" selected>-- Select Position --</option>
  {% set positions = craft.categories.group('position') %}
  {% for position in positions %}
  <option value="{{ position.slug }}">{{ position.title }}</option>
  {% endfor %}
</select>

<select name="state[]">
  <option value="" selected>-- Select State --</option>
  {% set states = craft.categories.group('state') %}
  {% for state in states %}
  <option value="{{ state.slug }}">{{ state.title }}</option>
  {% endfor %}
</select>

<select name="status[]">
  <option value="" selected>-- Select Status --</option>
  {% set statuses = craft.categories.group('status') %}
  {% for status in statuses %}
  <option value="{{ status.slug }}">{{ status.title }}</option>
  {% endfor %}
</select>

<select name="denomination[]">
  <option value="" selected>-- Select Denomination --</option>
  {% set denominations = craft.categories.group('denomination') %}
  {% for denomination in denominations %}
  <option value="{{ denomination.slug }}">{{ denomination.title }}</option>
  {% endfor %}
</select>

<div class="">
  <input type="submit" value="Search">
</div>

And here is what I have on Results Page:

{% set query = craft.request.getParam('q') %}
{% set position = craft.request.getParam('position') %}
{% set state = craft.request.getParam('state') %}
{% set status = craft.request.getParam('status') %}

{% set homeGrownParam = craft.request.getParam('homeGrown') %}
{% set preparedProduceParam = craft.request.getParam('preparedProduce') %}
{% set redTractorParam = craft.request.getParam('redTractor') %}

{% set positionCat = position ? craft.categories.group('position').slug(position).find() %}
{% set stateCat = state ? craft.categories.group('state').slug(state).find() %}
{% set statusCat = status ? craft.categories.group('status').slug(status).find() %}

{% set positionParam = positionCat ? {targetElement: ['and']|merge(positionCat)} %}
{% set stateParam = stateCat ? {targetElement: ['and']|merge(stateCat)} %}
{% set statusParam = statusCat ? {targetElement: ['and']|merge(statusCat)} %}

{% set relationParams = [positionParam, stateParam, statusParam]|filter %}

{% set entries = craft.entries({
    section: 'ministryJobs',
    relatedTo: relationParams ? ['and']|merge(relationParams) : null,
    search: query,
    homeGrown: homeGrownParam,
    preparedProduce: preparedProduceParam,
    redTractor: redTractorParam
}) %}

<div class="{{ cycle(['job-display-white', 'job-display-grey'], loop.index0) }}">

    <a href="{{ entry.url }}">
        <div class="col-1 post-data">{{ entry.postDate.format("m/d/y") }}</div>
        <div class="col-2 post-data job-position">{{ entry.position }}</div>
        <div class="col-3 post-data">{{ entry.church }}</div>
        <div class="col-4 post-data">{{ entry.city }}</div>
        <div class="col-5 post-data">{{ entry.state }}</div>
        <div style="clear: both;"></div>
    </a>

</div>

I am getting no results. I am not sure what I am doing wrong. Any help is greatly appreciated.

0

I might be missing something, but your code is missing a {% for entry in entries %} loop wrapped around your <div>.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.