Title: Sorting
Last modified: August 6, 2024

---

# Sorting

 *  [madinfinity](https://wordpress.org/support/users/madinfinity/)
 * (@madinfinity)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/sorting-60/)
 * Hello friend. Thanks for this cool plugin. I want to use it on a historical site,
   and I need to display historical dates of past years in a separate block.
   Everything
   is fine, except for sorting.Is it possible to display the headings in alphabetical
   order? Numbers by age.The thing is that in my historical event headings, annual
   events come first, and I need the years to be sorted by age.Now I use the eventon
   plugin for these purposes, it perfectly sorts my events in ascending order, but
   it works very slowly and in principle does not suit me.Here are some screenshots
   of how it works now on eventon and in your plugin. I want to get rid of Eventon.
   The only question is sorting. If there was an opportunity to somehow make sorting,
   I would be grateful. Thank youScreenshots:Sorting – [On This Day (by Room 34](https://jmp.sh/s/zuvRCQk9IpAZz22ZSWfp))
 * Sorting – [On This Day (by Room 34)](https://ibb.co/ygjZKMd)
   Correct sorting –
   [Eventon](https://jmp.sh/s/Zko2UqnMCZLHJdFpMtBf)
 * Correct sorting – [Eventon](https://ibb.co/pPrPgqd)
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fsorting-60%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [madinfinity](https://wordpress.org/support/users/madinfinity/)
 * (@madinfinity)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/sorting-60/#post-17938200)
 * Please!
 *  Plugin Author [Room 34 Creative Services, LLC](https://wordpress.org/support/users/room34/)
 * (@room34)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/sorting-60/#post-17944228)
 * Hi… the links to the screenshots are not working for me. However, as I understand
   it you’re trying to have the query for On This Day sort the returned posts alphabetically
   by title, rather than chronologically by publish date, is that correct? If so,
   you could use a bit of custom code in your theme, leveraging the [pre_get_posts](https://developer.wordpress.org/reference/hooks/pre_get_posts/)
   action. The main challenge would be targeting the correct queries so it’s not
   running on _every_ query. I think something like this should work, but I haven’t
   actually tested it:
 *     ```wp-block-code
       add_action('pre_get_posts', function($query) {  if (    !is_admin() && // Only run on front end    !$query->is_main_query() && // Don't run on main query    is_array($query->get('date_query')) && // Run if date_query is an array    !empty($query->get('monthnum')) && // Run if monthnum is specified    !empty($query->get('day') // Run if day is specified )) {    $query->set('orderby' => 'name');    $query->set('order', 'ASC');  }}, 10, 1);
       ```
   
 * There’s not a really simple way to determine if the query is for On This Day,
   so I loaded up as many specifics as I could.
 *  Thread Starter [madinfinity](https://wordpress.org/support/users/madinfinity/)
 * (@madinfinity)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/sorting-60/#post-17944755)
 * Thank you.
   Please tell me where I should put this code?Where should I upload 
   screenshots so you can see them?
 *  Plugin Author [Room 34 Creative Services, LLC](https://wordpress.org/support/users/room34/)
 * (@room34)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/sorting-60/#post-17956001)
 * The code can go in your theme’s `functions.php` file.
 * You can put the screenshots wherever you want… they’re just not there anymore
   on the sharing service you used.
 *  Thread Starter [madinfinity](https://wordpress.org/support/users/madinfinity/)
 * (@madinfinity)
 * [1 year, 9 months ago](https://wordpress.org/support/topic/sorting-60/#post-17956271)
 * Thank you
 *  Thread Starter [madinfinity](https://wordpress.org/support/users/madinfinity/)
 * (@madinfinity)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/sorting-60/#post-18019239)
 *     ```wp-block-code
       syntax error, unexpected token =, expecting )
       ```
   
 * Hello, I apologize, but this is what I got when I tried to use your code
 *  Plugin Author [Room 34 Creative Services, LLC](https://wordpress.org/support/users/room34/)
 * (@room34)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/sorting-60/#post-18019728)
 * Sorry, that was a careless mistake I would have caught if I had tested the code.
 * In the fourth line from the end, replace this:
 * `=>`
 * with this:
 * `,`
 *  Thread Starter [madinfinity](https://wordpress.org/support/users/madinfinity/)
 * (@madinfinity)
 * [1 year, 8 months ago](https://wordpress.org/support/topic/sorting-60/#post-18029232)
 * Thank you, it works

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Sorting’ is closed to new replies.

 * ![](https://ps.w.org/room-34-presents-on-this-day/assets/icon.svg?rev=2600649)
 * [On This Day (by Room 34)](https://wordpress.org/plugins/room-34-presents-on-this-day/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/room-34-presents-on-this-day/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/room-34-presents-on-this-day/)
 * [Active Topics](https://wordpress.org/support/plugin/room-34-presents-on-this-day/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/room-34-presents-on-this-day/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/room-34-presents-on-this-day/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [madinfinity](https://wordpress.org/support/users/madinfinity/)
 * Last activity: [1 year, 8 months ago](https://wordpress.org/support/topic/sorting-60/#post-18029232)
 * Status: not resolved