Support » Plugin: Display Posts - Easy lists, grids, navigation, and more » Dynamic sort of displayed posts

  • Resolved vatavazz

    (@vatavazz)


    Does this plugin have an inbuilt functionality for client-side sorting the posts according to different criteria (eg. alphabetically, by date), or a way to send another query and display those results instead?

    Hopefully, linking to a separate page with the shortcode using a different query is not the only solution.

    Thanks in advance.

    • This topic was modified 2 years, 4 months ago by vatavazz.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Bill Erickson

    (@billerickson)

    Yes, you can order by many different criteria. Here’s the full list: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    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 2 years, 4 months ago by vatavazz.
    Plugin Author Bill Erickson

    (@billerickson)

    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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Dynamic sort of displayed posts’ is closed to new replies.