Title: ksort() doesn&#8217;t sort array
Last modified: July 16, 2025

---

# ksort() doesn’t sort array

 *  Resolved [HeyBlondie](https://wordpress.org/support/users/heyblondie/)
 * (@heyblondie)
 * [11 months, 1 week ago](https://wordpress.org/support/topic/ksort-doesnt-sort-array/)
 * Hi … thank you again for this plugin.
 * I nearly have this working for the display of a grid of upcoming events and I’m
   using RRule also for single events. The issue I’m having is when recurring events
   are mixed with single date events and displaying them in correct date order.
 * Recurring events display first, regardless of the date.
 * I’ve been basing my code on your Advanced use example: [https://github.com/marcbelletre/acf-rrule?tab=readme-ov-file#advanced-usage](https://github.com/marcbelletre/acf-rrule?tab=readme-ov-file#advanced-usage)….
   but the ksort() doesn’t sort the array correctly, and events still don’t show
   in correct date order. This appears to be a known issue where ksort can’t sort
   a ‘date string’.
   I’ve tried inserting the date as strtotime($date) into the array,
   but that doesn’t work.
 * I’ve tried the suggested method for sorting such arrays, but that doesn’t work
   either:
   `uksort($dates, function($a, $b) { return strtotime($a) <=> strtotime(
   $b);});
 * Would love to hear if there might be known solutions to this please?
   I’ll keep
   looking in the meantime.
 * Thanks
 * Mianne
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fksort-doesnt-sort-array%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Thread Starter [HeyBlondie](https://wordpress.org/support/users/heyblondie/)
 * (@heyblondie)
 * [11 months ago](https://wordpress.org/support/topic/ksort-doesnt-sort-array/#post-18558827)
 * I actually now have this working – and (as I see it) there is an error in the
   sample code for Advanced Use.
 * The ‘ksort($dates)’ should be *outside* of the post loop! Once I did that, everything
   started working exactly as it should.
 * It appears the Github code needs rectifying (unless I’m mistaken? … but hey, 
   my code is now working perfectly)
 * Thanks

Viewing 1 replies (of 1 total)

The topic ‘ksort() doesn’t sort array’ is closed to new replies.

 * ![](https://ps.w.org/acf-rrule-field/assets/icon-256x256.png?rev=2498015)
 * [ACF RRule Field](https://wordpress.org/plugins/acf-rrule-field/)
 * [Support Threads](https://wordpress.org/support/plugin/acf-rrule-field/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-rrule-field/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-rrule-field/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-rrule-field/reviews/)

## Tags

 * [date order](https://wordpress.org/support/topic-tag/date-order/)

 * 1 reply
 * 1 participant
 * Last reply from: [HeyBlondie](https://wordpress.org/support/users/heyblondie/)
 * Last activity: [11 months ago](https://wordpress.org/support/topic/ksort-doesnt-sort-array/#post-18558827)
 * Status: resolved