<p>So in order to do this you have to reformat your code and your strategy a bit. You cant provide a Craft query as a link, all that does is grab an array from the database and it won't inherently print something out.</p>

<pre><code>&lt;li&gt;&lt;a href="{% set usersByFirstName = craft.users.search('sortAS', '{{ firstName}}') %}"&gt;A-Z&lt;/a&gt;&lt;/li&gt;
</code></pre>

<p>The best way to change the way your results are being sorted (if you want to do it via Twig and not something front-end like JS is to send the sort style through a query string.</p>

<p>So let's assume you are returning a list of users and you want to sort them by first name alpha ascending:</p>

<pre><code>{% set users = craft.users.order('firstName asc').find() %}
</code></pre>

<p>If you want to change the direction of the order create a link like this:</p>

<pre><code>&lt;a href="url/user-list?sort=desc"&gt;Sort Z-A&lt;/a&gt;
</code></pre>

<p>When the page reloads a new query parameter is available to you <code>sort</code>, you can get it with this code:</p>

<pre><code>{% set sort = craft.request.getParam('sort') %}
</code></pre>

<p>Now you can use that variable to alter the way your original query works. Something like this... starting over from scratch:</p>

<pre><code>{% if craft.request.getParam('sort')|length &gt; 0 %}

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

 {% else %}

    {% set sort = 'asc' %} {# default sort #}

 {% endif %}
</code></pre>

<p>Then in the Craft query, you could just user this instead of our original query above:</p>

<pre><code> {% set users = craft.users.order('firstName ' ~ sort).find() %}
</code></pre>

<p>Now when the page first loads you will get users sorted by <code>firstName asc</code> and when you click the filter it will reload with <code>firstName desc</code>.</p>

<p>You can apply this same query string method to all of the parameters. Getting variables like:</p>

<pre><code>{% set sortBy = craft.request.getParam('sortBy') %}
</code></pre>

<p>Where <code>sortBy</code> equals <code>firstName</code> or <code>lastName</code></p>

<p>That query string would look like:</p>

<pre><code>url/user-list?sort=desc&amp;sortby=firstName
</code></pre>

<p>And so on.</p>

CC BY-SA 3.0
2017-08-29T17:38:38.947Z
2017-08-29T17:38:38.947Z
Alan Miller
<p>***I have just realised I am mixing up my filtering and sorting. I have amended the question to try and make it a bit clearer.</p>

<p>I'm trying to use SuperSort plugin to run different filters, but I'm struggling as only the last filter gets applied. I would like to add the filter to a button or link, so that when the user clicks on it, it activates the filter. Any tips?</p>

<pre><code>&lt;h1&gt;search&lt;/h1&gt;

&lt;form action="{{ url('search') }}"&gt;
    &lt;input type="search" name="q" placeholder="Search"&gt;
    &lt;input type="submit" value="Go"&gt;
&lt;/form&gt;

{% set query = craft.request.getParam('q') %}
{% set users = craft.users.search(query).order('dateUpdated')|reverse %}

{% if users|length %}
    &lt;p&gt;&lt;/p&gt;
    &lt;ul&gt;
        &lt;span&lt;a href="{{ users.dateUpdated }}"&gt;{{ users|length }} results:&lt;/a&gt;&lt;/span&gt;
        &lt;li&gt;&lt;a href="{% set usersByFirstName = craft.users.search('sortAS', '{{ firstName}}') %}"&gt;A-Z&lt;/a&gt;&lt;/li&gt;

        &lt;li&gt;&lt;a href="{% set users = craft.users.search(query).order('firstName')|reverse%}"&gt;Z-A&lt;/a&gt;&lt;/li&gt;

        &lt;li&gt;&lt;a href="#"&gt;Nearby&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;Newest&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href="#"&gt;Oldest&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
{% endif %}
</code></pre>

<p>For example: </p>

<p>link#1 - sort A-Z
link#2 - sort dateUpdated</p>

CC BY-SA 3.0
2017-08-29T04:06:47.360Z
Can you clarify the question a bit more? I am not sure what information you are looking for. Thanks!
Alan Miller
CC BY-SA 3.0
2017-08-29T09:35:06.820Z
The filters are currently overwriting each other, so only the last filter applies. I'd like to use different filters like this:
link#1 - filter A-Z
link#2 - filter dateUpdated
Hope that makes more sense
Remco
<filter><plugin-supersort><link>
How can I let the user activate a particular SuperSort filter
# How can I let the user activate a particular SuperSort filter

(Asked by: username_0 on 2017-08-28)

***I have just realised I am mixing up my filtering and sorting. I have amended the question to try and make it a bit clearer.
I'm trying to use SuperSort plugin to run different filters, but I'm struggling as only the last filter gets applied. I would like to add the filter to a button or link, so that when the user clicks on it, it activates the filter. Any tips?
search


    
    


{% set query = craft.request.getParam('q') %}
{% set users = craft.users.search(query).order('dateUpdated')|reverse %}

{% if users|length %}
    
    
        {{ users|length }} results:
        A-Z

        Z-A

        Nearby
        Newest
        Oldest
    
{% endif %}

For example: 
link#1 - sort A-Z
link#2 - sort dateUpdated

**Tags:** filter, plugin-supersort, link

> **Comments:**
> **username_1**: Can you clarify the question a bit more? I am not sure what information you are looking for. Thanks!  
> **username_0**: The filters are currently overwriting each other, so only the last filter applies. I'd like to use different filters like this: link#1 - filter A-Z link#2 - filter dateUpdated Hope that makes more sense  

---

## 1 answers

### Answer by username_1 on 2017-08-29. Score: 4 | Accepted answer

So in order to do this you have to reformat your code and your strategy a bit. You cant provide a Craft query as a link, all that does is grab an array from the database and it won't inherently print something out.
A-Z

The best way to change the way your results are being sorted (if you want to do it via Twig and not something front-end like JS is to send the sort style through a query string.
So let's assume you are returning a list of users and you want to sort them by first name alpha ascending:
{% set users = craft.users.order('firstName asc').find() %}

If you want to change the direction of the order create a link like this:
Sort Z-A

When the page reloads a new query parameter is available to you sort, you can get it with this code:
{% set sort = craft.request.getParam('sort') %}

Now you can use that variable to alter the way your original query works. Something like this... starting over from scratch:
{% if craft.request.getParam('sort')|length > 0 %}

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

 {% else %}

    {% set sort = 'asc' %} {# default sort #}

 {% endif %}

Then in the Craft query, you could just user this instead of our original query above:
 {% set users = craft.users.order('firstName ' ~ sort).find() %}

Now when the page first loads you will get users sorted by firstName asc and when you click the filter it will reload with firstName desc.
You can apply this same query string method to all of the parameters. Getting variables like:
{% set sortBy = craft.request.getParam('sortBy') %}

Where sortBy equals firstName or lastName
That query string would look like:
url/user-list?sort=desc&sortby=firstName

And so on.


---

