Hello,
The nicest way to do it would be via AJAX with no page reload, but that’s beyond the scope of this plugin.
One option is to use a query variable to pass the selected order. The selector can be links to the current page with the [loop], with the order choice.
<a href="?sort=title">Order by name</a>
<a href="?sort=date">Order by date</a>
Then for the loop:
[pass global=query]
[loop type=post orderby='{SORT}' count=5]
[field title] - [field date]
...
[/loop]
[/pass]
This actually uses an undocumented parameter for [pass] – I’ll add this in the reference pages in the next update.
You can pass several parameters if you need.
<a href="?sort=date&order=ASC">Order by date from old to new</a>
...
[pass global=query]
[loop type=post orderby='{SORT}' order='{ORDER}']
...
[/loop]
[/pass]
I would put the {TAGS} inside quotes, in case it might be empty.
Hello,
I could not get it working until I noticed there was an update. I updated the plugin and now it’s working like a charm! Thank you for the fast reply and congrats for this awesome plugin.
It is correct to do this:
[if pass='{SORT}’]
[loop type=post orderby='{SORT}’]
[else]
[loop]
[/if]
because if I don’t give parameters in the url, no posts are displayed.
TYA
OK, I changed how this works in the newest update. When using global=query, you can specify the fields parameter:
[pass global=query fields=sort]
[loop type=post orderby='{SORT}']
...
[/loop]
[/pass]
This way, if the query variable sort doesn’t exist, the [pass] shortcode will know to remove {SORT} and leave an empty value – in which case the loop will default to sorting from most recent date.
Now it’s working as I wished. Thank you for the quick updates 🙂