diff --git a/includes/calendar-layout.php b/includes/calendar-layout.php
index 2494b72..d42dac9 100644
--- a/includes/calendar-layout.php
+++ b/includes/calendar-layout.php
@@ -81,6 +81,17 @@ function aa_events_occurrence_intersects_range( array $occurrence, DateTimeImmut
return null !== $occurrence_start && null !== $occurrence_end && $occurrence_end >= $occurrence_start && $end >= $start && $occurrence_start <= $end && $occurrence_end >= $start;
}
+/**
+ * Build a stable key for an event occurrence within a calendar render.
+ *
+ * @param mixed $post_id Event post ID.
+ * @param mixed $occurrence_index Zero-based occurrence index for the event.
+ * @return string
+ */
+function aa_events_calendar_occurrence_key( $post_id, $occurrence_index ) {
+ return (int) $post_id . '-' . (int) $occurrence_index;
+}
+
/**
* Clip an occurrence to a month and split it at week boundaries.
*
diff --git a/templates/calendar.php b/templates/calendar.php
index 46d271d..9b55e03 100644
--- a/templates/calendar.php
+++ b/templates/calendar.php
@@ -117,14 +117,15 @@ $events = new WP_Query(
foreach ( $events->posts as $event_id ) {
$event_title = get_the_title( $event_id );
$event_permalink = get_permalink( $event_id );
- foreach ( aa_events_get_occurrences( $event_id ) as $occurrence ) {
+ foreach ( aa_events_get_occurrences( $event_id ) as $occurrence_index => $occurrence ) {
if ( ! is_array( $occurrence ) || ! aa_events_occurrence_intersects_range( $occurrence, $month['month_start'], $month['month_end'] ) ) {
continue;
}
- $occurrence['post_id'] = (int) $event_id;
- $occurrence['title'] = $event_title;
- $occurrence['permalink'] = $event_permalink;
- $calendar_occurrences[] = $occurrence;
+ $occurrence['post_id'] = (int) $event_id;
+ $occurrence['title'] = $event_title;
+ $occurrence['permalink'] = $event_permalink;
+ $occurrence['calendar_occurrence_key'] = aa_events_calendar_occurrence_key( $event_id, $occurrence_index );
+ $calendar_occurrences[] = $occurrence;
}
}
@@ -211,7 +212,7 @@ $calendar_url = static function ( DateTimeImmutable $date ) use ( $calendar
/* translators: 1: event title, 2: complete event date and time range. */
$event_label = sprintf( __( '%1$s: %2$s', 'aa-events' ), $segment['title'], aa_events_format_occurrence( $segment ) );
?>
-
+