1

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!!

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!

|improve this answer|||||
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})     %}
|improve this answer|||||

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.