Hi, thanks for the swift reply. You did not understand what I was asking for: a feature to sort the posts client-side, eg, via a button. Think of it as a table, where you could click a header and order the items in ascending or descending order according to the clicked attribute.
Alternatively – a way to run another query, replacing the posts currently displayed.
A working solution could be coded using JS, but I’d prefer something native, or at least PHP-only.
Thanks in advance.
-
This reply was modified 8 years, 6 months ago by
vatavazz.
Sorry, after re-reading I see what you are asking.
You want the ability for a user looking at the page to be able to change the sort method.
No, this is not a built-in feature, but is something you could add.
First, create a dropdown menu (or list of links, or however you want to present it) with all the sorting options you want. This could be added automatically to the shortcode using the display_posts_shortcode_wrapper_open filter (controls the opening markup of the shortcode).
The links or select menu should reload the current page with a parameter added to the URL, like ?dps_order=ASC&dps_orderby=title
Then use the display_posts_shortcode_args filter to modify the query arguments if those URL parameters exist. Make sure it’s a whitelisted set of options rather than selecting any user input.
This is exactly what I want, thank you!