Update and add POST URL parameters How do you add extra parameters or update a parameter to an exiting POST URL?

ADD EXTRA PARAMETER

For example, I have a page at this address:

http://localhost/shop/?color=red&amp;order=title


And in my twig I want to add a parameter like this:

http://localhost/shop/?color=red&amp;order=title&amp;sort=asc
http://localhost/shop/?color=red&amp;order=title&amp;sort=asc&amp;limit=10


UPDATE PARAMETER

For example, I have a page at this address:

http://localhost/shop/?color=red&amp;order=title


And in my twig I want to update a parameter like this:

http://localhost/shop/?color=blue&amp;order=title
http://localhost/shop/?color=red&amp;order=price
If i'm not mistaking, craft.request.getQuery() returns an array filled with all $_GET key-value pairs, so in your case:

{% set queryParams = craft.request.getQuery() %}


will let you do:

// Do with it what you like ...
{% set queryParams = queryParams | without(key) %} // Removes a param
{% set queryParams = queryParams | merge([{ 'limit' : 10 }]) %} // Adds a param
{% set queryParams['order'] = 'price' %} // Changes a param


After doing what you need to do, you can rebuild the query string:

{% set queryString = '' %}
{% for key, value in queryParams %}
    {% set queryString = loop.first ? '?' ~ key ~ '=' ~ value : '&amp;amp;' ~ key ~ '=' ~ value %}
{% endfor %}
{% redirect(siteUrl ~ queryString) %}