Answers.Body: <p>OK, this should be a working code example: </p>
  
  <pre><code>{% set queryParams = craft.app.request.queryParams %}
  {% for key, value in queryParams %}
    {% set url = siteUrl ~ craft.app.request.fullPath %}
    {% set arr = queryParams | filter((v, k) =&gt; k != key) %}
    {% if arr|length &gt; 0 %} 
      {% set url = url ~ '?' ~ arr|url_encode %}
    {% endif %}
    &lt;a href="{{url}}"&gt;{{key}} {{value}} x&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>Line by line:</p>
  
  <p>Create an array based on the current <a href="https://docs.craftcms.com/api/v3/craft-web-request.html" rel="nofollow noreferrer">request parameters</a>:</p>
  
  <pre><code>{% set queryParams = craft.app.request.queryParams %}
  </code></pre>
  
  <p>Loop through the array and get the key/value pair:</p>
  
  <pre><code>{% for key, value in queryParams %}
  </code></pre>
  
  <p>While inside the loop, get the URL that we want to modify, minus the request params:</p>
  
  <pre><code>{% set url = siteUrl ~ craft.app.request.fullPath %}
  </code></pre>
  
  <p><a href="https://twig.symfony.com/doc/2.x/filters/filter.html" rel="nofollow noreferrer">Filter a local copy of the array</a> to remove the current key:</p>
  
  <pre><code>{% set arr = queryParams | filter((v, k) =&gt; k != key) %}
  </code></pre>
  
  <p>If there are any parameters left, modify the URL we previously set with the remaining parameters:</p>
  
  <pre><code>{% if arr|length &gt; 0 %} 
    {% set url = url ~ '?' ~ arr|url_encode %}
  {% endif %}
  </code></pre>
  
  <p>Output the link that will load the page without the current parameter.</p>
  
  <pre><code>&lt;a href="{{url}}"&gt;{{key}} {{value}} x&lt;/a&gt;
  </code></pre>
  
  <p>I would probably do this in a macro to keep the template code a bit cleaner and easy to read.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-14T01:53:48.920Z
Answers.Text: THANK YOU!! This worked great! There's one tiny thing I had a question on: `p=page-slug` is added to the URL. I get why and it's not critical at all, but is there a way to remove that at all? Again, no biggie!
Answers.UserDisplayName: A Herrera
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-14T22:44:41.220Z
Answers.Text: Hmm, I'm not sure, I didn't see that when I was testing this out. But the filter function does accept multiple conditions so this might work: {% set arr = queryParams | filter((v, k) => k != key and k != 'p') %}
Answers.UserDisplayName: Dalton Rooney
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-13T03:21:15.110Z
Answers.LastActivityDate: 2020-05-13T03:21:15.110Z
Answers.UserDisplayName: Dalton Rooney
Body: <p>I'm working on a site with some filters that result in a page with a URL similar to this:
  <code>domain.com/led-products?series=67&amp;efficacy=1000to5000&amp;lumens=over150</code></p>
  
  <p>That results page contains buttons/links like so:</p>
  
  <p><code>[Series Name x]
   [1,000 to 5,000 Efficacy x]
   [Over 150 Lumens x]</code></p>
  
  <p>Clicking on one of those would remove that filter. Let's say a user clicks on Series Name to remove that filter, the resulting URL would then be: <code>domain.com/led-products?efficacy=1000to5000&amp;lumens=over150</code></p>
  
  <p>My problem is that I have no idea how to get that filter/parameter removal functionality in Craft. Does this require a JS solution?</p>
  
  <p>I've played around with something <a href="https://craftcms.stackexchange.com/a/2484/256">like this</a> and can't seem to get it to work for my needs.</p>
  
  <p>Help?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-12T22:36:39.717Z
Comments.Text: Are you trying to do this with javascript, or just reload the page with the modified query string?
Comments.UserDisplayName: Dalton Rooney
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-05-13T02:29:57.657Z
Comments.Text: Honestly, whatever is going to be easiest. I'm totally fine with reloading the page with the modified query string.
Comments.UserDisplayName: A Herrera
Tags: <params><querystring>
Title: Easily update the query string with a link
ThreadText: # Easily update the query string with a link
  
  (Asked by: username_0 on 2020-05-12)
  
  I'm working on a site with some filters that result in a page with a URL similar to this:
  `domain.com/led-products?series=67&efficacy=1000to5000&lumens=over150`
  
  That results page contains buttons/links like so:
  
  `[Series Name x]
  [1,000 to 5,000 Efficacy x]
  [Over 150 Lumens x]`
  
  Clicking on one of those would remove that filter. Let's say a user clicks on Series Name to remove that filter, the resulting URL would then be: `domain.com/led-products?efficacy=1000to5000&lumens=over150`
  
  My problem is that I have no idea how to get that filter/parameter removal functionality in Craft. Does this require a JS solution?
  
  I've played around with something [like this](https://craftcms.stackexchange.com/a/2484/256) and can't seem to get it to work for my needs.
  
  Help?
  
  **Tags:** params, querystring
  
  > **Comments:**
  > **username_1**: Are you trying to do this with javascript, or just reload the page with the modified query string?  
  > **username_0**: Honestly, whatever is going to be easiest. I'm totally fine with reloading the page with the modified query string.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-05-13. Score: 1 | Accepted answer
  
  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="{{url}}">{{key}} {{value}} x</a>
  {% endfor %}
  
  ```
  
  Line by line:
  
  Create an array based on the current [request parameters](https://docs.craftcms.com/api/v3/craft-web-request.html):
  
  ```
  {% set queryParams = craft.app.request.queryParams %}
  
  ```
  
  Loop through the array and get the key/value pair:
  
  ```
  {% for key, value in queryParams %}
  
  ```
  
  While inside the loop, get the URL that we want to modify, minus the request params:
  
  ```
  {% set url = siteUrl ~ craft.app.request.fullPath %}
  
  ```
  
  [Filter a local copy of the array](https://twig.symfony.com/doc/2.x/filters/filter.html) to remove the current key:
  
  ```
  {% set arr = queryParams | filter((v, k) => k != key) %}
  
  ```
  
  If there are any parameters left, modify the URL we previously set with the remaining parameters:
  
  ```
  {% if arr|length > 0 %} 
    {% set url = url ~ '?' ~ arr|url_encode %}
  {% endif %}
  
  ```
  
  Output the link that will load the page without the current parameter.
  
  ```
  <a href="{{url}}">{{key}} {{value}} x</a>
  
  ```
  
  I would probably do this in a macro to keep the template code a bit cleaner and easy to read.
  
  > **Comments:**
  > **username_0**: THANK YOU!! This worked great! There's one tiny thing I had a question on: `p=page-slug` is added to the URL. I get why and it's not critical at all, but is there a way to remove that at all? Again, no biggie!  
  > **username_1**: Hmm, I'm not sure, I didn't see that when I was testing this out. But the filter function does accept multiple conditions so this might work: {% set arr = queryParams | filter((v, k) => k != key and k != 'p') %}  
  
  ---
  
  