2

I have entries in a channel called "shorts". Each of those entries has a field called "size" that can be a value of small, medium or large.

I have created a form where I want users to be able to filter entries where the field could match small and medium (for example). I am using checkboxes on my front end form and a drop down field on the Craft admin form.

The URL I'm utilizing looks like this: http://domain.com/search/results?size=small&size=medium

But only the mediums are being displayed.

This is my code. I am not sure how to join the two together so smalls and mediums are displayed:

{% set params = {section: 'shorts', limit: null}
{% if craft.request.getParam('size') %}
{% set params = params|merge({'size':size}) %}
{% endif %}
3

The main problem is your URL isn't formatted correctly. You need brackets after each 'size' parameter to make an array of those values. Otherwise, it only picks up the last value.

http://domain.com/search/results?size[]=small&size[]=medium

Then you can do something like this:

{% set sizeQuery = craft.request.getParam('size') %}

{% set params = {section: 'shorts', limit: null} %}

{% if sizeQuery %}
  {% set params = params|merge({'size':sizeQuery}) %}
{% endif %}

Also, you can use the dump() function to test what craft.request.getParam('size') is finding in your URL.

{{ dump(sizeQuery) }}

This URL: http://domain.com/search/results?size=small&size=medium

... returns string(5) "medium".

But this URL: http://domain.com/search/results?size[]=small&size[]=medium

... returns array(2) { [0]=> string(5) "small" [1]=> string(5) "medium" }.

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.