<p>Wow, ok so I spent all day on this, I seem to have gotten it to work, but to be honest, I'm not 100% sure why/how this works. Anyways, I altered the code in the answer given here: <a href="https://craftcms.stackexchange.com/questions/6937/searching-a-specific-section-by-four-different-types-of-parameters">Searching a specific section by four different types of parameters?</a></p>

<p>And ended with this:</p>

<pre><code>{% set zoekschip = craft.request.getParam('zoekschip') %}

 {% set params = {
section:        'tours',
limit:      null
} %}
                   {% set relatedParams = ['and'] %}


{# plaats #}
{% if craft.request.getParam('zoekplaats') %}
{% set plaats = craft.request.getParam('zoekplaats') %}
{% set params = params|merge({'startloc':plaats}) %}
{% endif %}


{# Schip #}
{% if craft.request.getParam('zoekschip') %}
{% set zoekschip = craft.entries.section('ships').shipName(craft.request.getParam('shipName')).first %}
{% set relatedParams = relatedParams|merge([{ targetElement:zoekschip }]) %}
{% endif %}

                        {# add relatedParams to params #}
{% if relatedParams|length &gt; 1 %}
{% set params = params|merge({'relatedTo':relatedParams}) %}
{% endif %}

{# perform search #}
{% set searchParams = craft.request.getParam('q') %}
{% set entries = craft.entries(params).search(searchParams|trim) %}




                            {% for entry in entries %}
..output..

{% endfor %}
</code></pre>

<p>Now, this works, it's pretty awesome, and after examining I understand it, and have a better understanding of how the</p>

<pre><code>  relatedTo: {targetElement:  } 
</code></pre>

<p>works :)</p>

<p>My next challenge, is to add another search param, regarding the dates.
The tours section currently has a matrix field which has one block, called 'vertrekdatum'. (departuredate) How I add the date to the param, and check whether any tour has that date in their blocks, and output if so..?</p>

<p>Thanks heaps in advanced!</p>

CC BY-SA 3.0
2015-09-22T17:51:41.087Z
2015-09-22T18:39:03.673Z
2017-04-13T12:51:00.200Z
Niels
<p>This is what I've come up with so far, with no results:</p>

<pre><code>{# datum #}
{% if craft.request.getParam('zoekdatum') %}
 {% set zoekdatum = craft.request.getParam('zoekdatum') %}
{% set data = data.type('vertrekdatum')| date('dd/mm/yyyy') %}
                      {% set params = params|merge({'data':zoekdatum})     %}
</code></pre>

CC BY-SA 3.0
2015-09-22T19:32:41.480Z
2015-09-22T19:32:41.480Z
Niels
<p>I'm requesting entries through a search field like so:</p>

<pre><code>{% set params = {
  section:      'tours',
  startloc:     craft.request.getParam('zoekplaats')
} %}


{% for entry in craft.entries(params) %}
...etc..
{% endfor %}
</code></pre>

<p>which works fine. However, as soon as the 'startloc' field type becomes an 'entry' (thus a relation) I can't simply state 'startloc:' anymore, as it has become an entire object. However, I'm quite limited to the syntax I can use within that params field. </p>

<p>I've tried many things but can't really figure it out. Anyone that knows what the correct way to do it would be?</p>

<p>Thanks a lot!!</p>

<relations><search>
using craft.request.getParam to filter by relations
# using craft.request.getParam to filter by relations

(Asked by: username_0 on 2015-09-22)

I'm requesting entries through a search field like so:
{% set params = {
  section:      'tours',
  startloc:     craft.request.getParam('zoekplaats')
} %}


{% for entry in craft.entries(params) %}
...etc..
{% endfor %}

which works fine. However, as soon as the 'startloc' field type becomes an 'entry' (thus a relation) I can't simply state 'startloc:' anymore, as it has become an entire object. However, I'm quite limited to the syntax I can use within that params field. 
I've tried many things but can't really figure it out. Anyone that knows what the correct way to do it would be?
Thanks a lot!!

**Tags:** relations, search

---

## 2 answers

### Answer by username_0 on 2015-09-22. Score: 1

Wow, ok so I spent all day on this, I seem to have gotten it to work, but to be honest, I'm not 100% sure why/how this works. Anyways, I altered the code in the answer given here: Searching a specific section by four different types of parameters?
And ended with this:
{% set zoekschip = craft.request.getParam('zoekschip') %}

 {% set params = {
section:        'tours',
limit:      null
} %}
                   {% set relatedParams = ['and'] %}


{# plaats #}
{% if craft.request.getParam('zoekplaats') %}
{% set plaats = craft.request.getParam('zoekplaats') %}
{% set params = params|merge({'startloc':plaats}) %}
{% endif %}


{# Schip #}
{% if craft.request.getParam('zoekschip') %}
{% set zoekschip = craft.entries.section('ships').shipName(craft.request.getParam('shipName')).first %}
{% set relatedParams = relatedParams|merge([{ targetElement:zoekschip }]) %}
{% endif %}

                        {# add relatedParams to params #}
{% if relatedParams|length > 1 %}
{% set params = params|merge({'relatedTo':relatedParams}) %}
{% endif %}

{# perform search #}
{% set searchParams = craft.request.getParam('q') %}
{% set entries = craft.entries(params).search(searchParams|trim) %}




                            {% for entry in entries %}
..output..

{% endfor %}

Now, this works, it's pretty awesome, and after examining I understand it, and have a better understanding of how the
  relatedTo: {targetElement:  } 

works :)
My next challenge, is to add another search param, regarding the dates.
The tours section currently has a matrix field which has one block, called 'vertrekdatum'. (departuredate) How I add the date to the param, and check whether any tour has that date in their blocks, and output if so..?
Thanks heaps in advanced!


---

### Answer by username_0 on 2015-09-22. Score: 0

This is what I've come up with so far, with no results:
{# datum #}
{% if craft.request.getParam('zoekdatum') %}
 {% set zoekdatum = craft.request.getParam('zoekdatum') %}
{% set data = data.type('vertrekdatum')| date('dd/mm/yyyy') %}
                      {% set params = params|merge({'data':zoekdatum})     %}


---

