From 3d7adaf815375c7f35168e0bcb12c56533b9598b Mon Sep 17 00:00:00 2001 From: Akhilesh Goud Date: Fri, 16 Jan 2026 19:29:35 +0530 Subject: [PATCH 1/2] Add reverse chronological order option for list view - Add admin setting checkbox for reverse chronological order in list view - Modify event sorting to support reverse chronological order (newest first) - Sort both daily events and events within each day in reverse order when enabled - Fixes issue where calendar settings produce no events in the list Related to ClickUp task: https://app.clickup.com/t/86cyyzbge --- .../admin/default-calendar-admin.php | 19 ++++++++++ .../calendars/views/default-calendar-list.php | 36 ++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/includes/calendars/admin/default-calendar-admin.php b/includes/calendars/admin/default-calendar-admin.php index 7eaaa588..fd5af42f 100644 --- a/includes/calendars/admin/default-calendar-admin.php +++ b/includes/calendars/admin/default-calendar-admin.php @@ -221,6 +221,25 @@ public function add_settings_meta_calendar_panel($post_id) ), 'value' => 'yes' == $compact ? 'yes' : 'no', ]); + ?> + + + + + + 'checkbox', + 'name' => '_default_calendar_reverse_chronological_order', + 'id' => '_default_calendar_reverse_chronological_order', + 'tooltip' => __( + 'Display events in reverse chronological order (newest first) instead of chronological order (oldest first).', + 'google-calendar-events' + ), + 'value' => 'yes' == $reverse_order ? 'yes' : 'no', + ]); ?> diff --git a/includes/calendars/views/default-calendar-list.php b/includes/calendars/views/default-calendar-list.php index fe27b696..b6bec336 100644 --- a/includes/calendars/views/default-calendar-list.php +++ b/includes/calendars/views/default-calendar-list.php @@ -390,7 +390,13 @@ private function get_events($timestamp) } } - ksort($daily_events, SORT_NUMERIC); + // Sort daily events - reverse if reverse chronological order is enabled + $reverse_order = get_post_meta($calendar->id, '_default_calendar_reverse_chronological_order', true) == 'yes'; + if ($reverse_order) { + krsort($daily_events, SORT_NUMERIC); + } else { + ksort($daily_events, SORT_NUMERIC); + } if (!empty($paged_events)) { $first_event = array_slice($paged_events, 0, 1, true); @@ -514,18 +520,31 @@ private function get_heading() * @since 3.1.28 * @access private */ - private static function cmp($a, $b) + private static function cmp($a, $b, $reverse = false) { if ($a->start == $b->start) { if ($a->title == $b->title) { return 0; } - return $a->title < $b->title ? -1 : 1; + $title_cmp = $a->title < $b->title ? -1 : 1; + return $reverse ? -$title_cmp : $title_cmp; } else { - return $a->start < $b->start ? -1 : 1; + $time_cmp = $a->start < $b->start ? -1 : 1; + return $reverse ? -$time_cmp : $time_cmp; } } + /** + * Comparison function for reverse chronological order. + * + * @since 3.x.x + * @access private + */ + private function cmp_reverse($a, $b) + { + return self::cmp($a, $b, true); + } + /** * Make a calendar list of events. * @@ -550,6 +569,9 @@ private function draw_list($timestamp, $id = 0) } } + // Check if reverse chronological order is enabled + $reverse_order = get_post_meta($calendar->id, '_default_calendar_reverse_chronological_order', true) == 'yes'; + $now = $calendar->now; $current_events = $this->get_events($timestamp); $format = $calendar->date_format; @@ -660,7 +682,11 @@ private function draw_list($timestamp, $id = 0) $count = 0; foreach ($events as $day_events): - usort($day_events, [$this, 'cmp']); + if ($reverse_order) { + usort($day_events, [$this, 'cmp_reverse']); + } else { + usort($day_events, [$this, 'cmp']); + } foreach ($day_events as $event): if ($event instanceof Event): From b2028e87dd9b747bb27978539d908768fc191fcf Mon Sep 17 00:00:00 2001 From: Akhilesh Goud Date: Fri, 16 Jan 2026 19:41:20 +0530 Subject: [PATCH 2/2] Add test-class to list view panel field --- includes/calendars/admin/default-calendar-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/calendars/admin/default-calendar-admin.php b/includes/calendars/admin/default-calendar-admin.php index fd5af42f..5a86bc93 100644 --- a/includes/calendars/admin/default-calendar-admin.php +++ b/includes/calendars/admin/default-calendar-admin.php @@ -152,7 +152,7 @@ public function add_settings_meta_calendar_panel($post_id) ?> - +