14

You're actually closer than you might think. All you need to do is add your field handles as parameters. I prefer to use the hash style of declaring parameters but either way will work, I just find this easier to read. {% set params = { section : 'events', order : 'eventDate asc', eventDate : '>=' ~ now, eventType : 'green', limit : '10' } %} {...


7

The issue with your current code is that you're looping over each type/size category, creating a parameter in your relatedTo query for each one. This means that you're currently creating a query that looks like this: relatedTo([ 'and', { targetElement: 1 }, { targetElement: 2 }, { targetElement: 3 }, { targetElement: 4 } ]) ...which, ...


4

A parameter with no value set returns an empty string '' for craft.request.getParam(). But if the whole parameter is not included at all, it returns null. This means you can test for null (→ see Twig docs) like so: {% if craft.request.getParam('myparam') is not null %} My Parameter is included in the query string! {% endif %}


3

This question is not really Craft related. Since you just don't send a valid request. You can't send one key multiple times unless you do it in an array. The php $_GET is a simple array with all your values and you overwrite them again and again. https://stackoverflow.com/questions/5098397/how-to-pass-an-array-in-get-in-php


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 = {...


2

Using the corrected checkbox name name=checkValue[] the submitted values ?checkValue%5B%5D=12345&checkValue%5B%5D=23456&checkValue%5B%5D=34567 are converted to an array. The array values can now be accessed using {% set checkVals = craft.request.getQuery('checkValue') %} {{ checkVals[1] }} {# outputs 23456 #} or {% for cVal in checkVals %} {...


2

You can do this by getting all the params in the url that have the same name and joining them into a single string which you can use in your Twig template. Note this code is untested but is based on something I've recently done. This example only uses categories but it's possible to expand it to search custom fields and/or add a free text search too. {# ...


2

You can do this completely in the template. Have the structure entries resolve to a route like gallery/_router and then inside that template you could use this code to include the template of your choice: {% switch craft.app.request.getParam('type') %} {% case "gallery" %} {% include "gallery/_entry" %} {% case "anotherParam" %} ...


2

Yes, you can do something like that. I built something very similar a few months ago where I checked for a query parameter in the URL when the page loaded, created a cookie with it using the Cookies plugin so I could access it in twig, then appended that query parameter to a donation button on other pages. Cookies: https://plugins.craftcms.com/cookies You ...


2

I think we need more information to be able to consider possible solutions. I personally wouldn't do anything in Craft, rewriting this URL before it hits the application would be cleaner. I don't know if it's possible to configure the 'action' parameter name in Craft so let's assume not. Are the referring URLs always the same? In other words, is the visitor ...


1

That's just the way forms work in html. If you don't want to use a POST method, (because that would make the results not URL-addressable at all), I'd recommend using an intermediary Twig template to perform a redirect based on what parameters exist - i.e., set your form action to search/process and in that template write a load of conditional statements to ...


1

OK, this should be a working code example: {% set queryParams = craft.app.request.queryParams %} {% for key, value in queryParams %} {% set url = siteUrl ~ craft.app.request.fullPath %} {% set arr = queryParams | filter((v, k) => k != key) %} {% if arr|length > 0 %} {% set url = url ~ '?' ~ arr|url_encode %} {% endif %} <a href="{{...


1

The same way as entry is available if you hit an entry, the variable category is available if you hit a category. Thus the following code: {% if category is defined %} {# Specific category selected #} {% else %} {# No specific category selected #} {% endif %}


1

I think you're going to have to go up the chain to where the request starts - i.e. the server config. Rewrite all urls matching api?action=... to somewhere else. If you're using nginx it'd be something like rewrite /api/$arg_action last;


1

Here's something I've got for filtering news by author and by category. You might be able to re-work it for your needs? From a page URL being: http://project.com/news?&cat=CATEGORY&author=NAME {% set query = {} %} {% set categoryParam = craft.app.request.getParam('cat') %} {% set authorParam = craft.app.request.getParam('author') %} {% set ...


1

I found a way to use the RetconHTML plugin for what I wanted. I just utilized the Attr filter and it worked the way I wanted. I had to also remove the way Retcon would add spaces to appended strings. {{ block.paragraph | retconAttr('a', { href : '?some_text' ~ entry.title|kebab }, false) }} By including false, it adds to the already existing href, rather ...


1

Products can be queried by the product types type (a handle or ProductTypeModel) or typeId the ID of the type. In a template this would look like: craft.commerce.products.typeId([1,3,4]).find() or craft.commerce.products.type(['new','another']).find() This is as per the parameter value syntax: https://craftcms.com/docs/templating/elementcriteriamodel#...


1

This sounds similar to your issue, have a look. People provided a solution there, it apparently might have something to do with your .htaccess file. getParam not working on live server?


1

You may be able to piggyback off of this answer on combining arrays of EntryModels, by providing the template with an array of dateQuery conditions. For each date condition, you could retrieve the entries as you're doing above, and then combine them with the previous results using the method in that answer. You can then call {% paginate %} using the final ...


1

The easiest way to do this is to create an array of tag ids for tags that should be active. I would use a comma to separate multiple tags in your query string since the browser interprets a plus sign as a space. For example, if your tags were "New Videos" and "Maths" the url would look like this: domain.com/learning/resources?tags=New+Videos,Maths First, ...


1

Perhaps not the most elegant solution, but this works: {% set queryTags = craft.request.getQuery('tags') %} {% for tag in craft.tags.relatedTo(resourceTags) %} <a href="{% if tags == "" %}/learning/resources?tags={{ tag.title|kebab }}{% else %}/learning/resources?tags={{ tags|replace(' ', '+') }}+{{ tag.title|kebab }}{% endif %}" class="btn ...


1

You can use the defaultValue to determine if the value is there or not. {% if craft.request.getParam('myVar', -1) != -1 %} myVar is here! {% else %} myVar is missing... {% endif %}


Only top voted, non community-wiki answers of a minimum length are eligible