Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save elimn/99bf67696bb3e1be85d9c4b0300314c5 to your computer and use it in GitHub Desktop.
Save elimn/99bf67696bb3e1be85d9c4b0300314c5 to your computer and use it in GitHub Desktop.
MT | TEC | Customized version of the Category Filter that includes CSS classes for subcategories
<?php
/**
* Customized version of the Category Filter that includes CSS classes for subcategories
* New filter available in WP-Admin > Events > Settings > Filters
*/
if ( class_exists( 'Tribe__Events__Filterbar__Filters__Category' ) ) {
class Tribe__Events__Filterbar__Filters__Category_Custom extends Tribe__Events__Filterbar__Filters__Category {
/**
* Flatten out the hierarchical list of event categories into a single list of values,
* applying formatting (non-breaking spaces) to help indicate the depth of each nested
* item.
*
* @param array $term_items
* @param array $existing_list
* @return array
*/
protected function flattened_term_list( array $term_items, array $existing_list = null ) {
// Pull in the existing list when called recursively
$flat_list = is_array( $existing_list ) ? $existing_list : array();
// Add each item - including nested items - to the flattened list
foreach ( $term_items as $term ) {
$flat_list[] = array(
'name' => $term->name,
'value' => $term->term_id,
'data' => array( 'slug' => $term->slug ),
'class' => 'tribe-events-category-' . $term->slug . ' tribe-events-subcategory-depth-' . $term->depth,
);
if ( ! empty( $term->children ) ) {
$child_items = $this->flattened_term_list( $term->children, $existing_list );
$flat_list = array_merge( $flat_list, $child_items );
}
}
return $flat_list;
}
}
new Tribe__Events__Filterbar__Filters__Category_Custom( __( 'Category Custom', 'tribe-events-filter-view' ), 'categorycustom' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment