• Resolved grovevilleumc

    (@grovevilleumc)


    I am aggregating google workspace calendars from church leaders to be displayed on the church website. Sometimes, church leaders are also members of committees not their own and so they have their own events on their calendar as well as the events of other committees they attend. The example is on the page shared on Monday April 20 – Communications Meeting. I only want one instance of this event being displayed. How do I filter duplicates out?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author LBell

    (@lbell)

    Howdy! That’s beyond the scope of this plugin. Sorry.

    Thread Starter grovevilleumc

    (@grovevilleumc)

    Thank you. I have found snippets of php like these but so far they haven’t worked, I think largely because they are just hypothetical. Can you suggest how I might hook into your plugin to implement something like this?

    Thanks again.

    add_filter(‘hycal_events’, function($events) {
    $unique = [];
    $output = [];

    foreach ($events as $event) {
        // Create a unique key based on title + start date
        $key = md5($event['title'] . $event['start']);
    
        if (!isset($unique[$key])) {
            $unique[$key] = true;
            $output[] = $event;
        }
    }
    
    return $output;

    });

    /**

    • Prevent duplicate events in Hydrogen Calendar Embeds
    • Place this in your theme’s functions.php or a custom plugin.
      */

    // Hook into Hydrogen Calendar Embeds event filter
    add_filter(‘hydrogen_calendar_events’, ‘my_remove_duplicate_calendar_events’);

    function my_remove_duplicate_calendar_events($events) {
    if (!is_array($events)) {
    return $events; // Safety check
    }

    $unique = [];
    $filtered = [];
    
    foreach ($events as $event) {
        // Create a unique key based on UID + start date
        // Adjust keys if your ICS feed uses different field names
        $uid   = isset($event['uid']) ? $event['uid'] : '';
        $start = isset($event['start']) ? $event['start'] : '';
    
        $key = md5($uid . '|' . $start);
    
        if (!isset($unique[$key])) {
            $unique[$key] = true;
            $filtered[] = $event;
        }
    }
    
    return $filtered;

    }

    Plugin Author LBell

    (@lbell)

    That would be the right track.

    For a non-exhaustive (and admitted AI-generated) doc of hooks available, see here: https://github.com/lbell/hydrogen-calendar-embeds/blob/master/docs/hooks.md

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

You must be logged in to reply to this topic.