<?php
if (!defined('ABSPATH')) exit;
$all_departments = []; // Initialize an array to store all departments
foreach ($all_members as $member) {
    if (isset($member['departments']) && is_array($member['departments'])) {
        $all_departments = array_merge($all_departments, $member['departments']);
    }
}
$all_departments = array_unique($all_departments); // Remove duplicate departments
?>
<div class="department-filter" data-selected-style="<?php echo esc_attr($selected_style); ?>">
    <ul id="department-selector">
        <li data-value="all" class="active">All Departments</li>
        <?php foreach ($all_departments as $department): ?>
            <?php if (!empty($department)) { ?>
                <li data-value="<?php echo esc_attr($department); ?>"> <?php echo esc_html($department); ?></li>
            <?php } ?>
        <?php endforeach; ?>
    </ul>
</div>