-
-
Save andrasguseo/13a54b311a8cc471ca0522ac7f40ebc5 to your computer and use it in GitHub Desktop.
Filter Bar - Template override to hide unwanted filter bar categories when using a dropdown or a checkbox.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* View: Checkbox Component | |
* | |
* Override this template in your own theme by creating a file at: | |
* [your-theme]/tribe/events-filterbar/v2_1/components/checkbox.php | |
* | |
* See more documentation about our views templating system. | |
* | |
* @link http://evnt.is/1aiy | |
* | |
* @var string $label Label for the checkbox. | |
* @var string $value Value for the checkbox. | |
* @var string $id ID of the checkbox. | |
* @var string $name Name attribute for the checkbox. | |
* @var boolean $checked Whether the checkbox is checked or not. | |
* | |
* @version 5.0.0 | |
* | |
*/ | |
?> | |
<?php | |
/* Start Customizations */ | |
// Check if event category AND checkbox | |
if ( | |
$data['name'] == 'tribe_eventcategory[]' | |
&& $data['type'] == 'checkbox' | |
) { | |
// Set up the unwanted categories by label | |
$unwanted_category_labels = [ | |
'C One', | |
'C Two', | |
]; | |
// Bail if the current category is an unwanted one. | |
if ( in_array( $data['label'], $unwanted_category_labels) ) { | |
return; | |
} | |
} | |
/* End Customizations */ | |
?> | |
<div | |
class="tribe-filter-bar-c-checkbox tribe-common-form-control-checkbox" | |
data-js="tribe-filter-bar-c-checkbox" | |
> | |
<input | |
class="tribe-common-form-control-checkbox__input" | |
id="<?php echo esc_attr( $id ); ?>" | |
name="<?php echo esc_attr( $name ); ?>" | |
type="checkbox" | |
value="<?php echo esc_attr( $value ); ?>" | |
<?php checked( $checked ); ?> | |
data-js="tribe-filter-bar-c-checkbox-input" | |
/> | |
<label | |
class="tribe-common-form-control-checkbox__label" | |
for="<?php echo esc_attr( $id ); ?>" | |
> | |
<?php echo esc_html( $label ); ?> | |
</label> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* View: Dropdown Component | |
* | |
* Override this template in your own theme by creating a file at: | |
* [your-theme]/tribe/events-filterbar/v2_1/components/dropdown.php | |
* | |
* See more documentation about our views templating system. | |
* | |
* @link http://evnt.is/1aiy | |
* | |
* @var string $value Value for the dropdown. | |
* @var string $id ID of the dropdown. | |
* @var string $name Name attribute for the dropdown. | |
* @var array<array> $options Options for the dropdown. | |
* | |
* @version 5.0.0 | |
* | |
*/ | |
/* Start Customizations */ | |
if ( $name == 'tribe_eventcategory[]' ) { // You can use 'tribe_tags[]' for tags { | |
// Unset unwanted categories | |
foreach ( $options as $i => $category ) { | |
// Prevent "undefined index" notice | |
if ( ! isset( $category["text"] ) ) { | |
return; | |
} | |
// Set your unwanted category names here | |
if ( "Event Category 1" === $category['text'] ) { | |
unset( $options[$i] ); | |
} | |
} | |
// Reindex the array | |
$options = array_values( $options ); | |
} | |
/* End Customizations */ | |
$classes = [ 'tribe-filter-bar-c-dropdown' ]; | |
foreach ( $options as $option ) { | |
$term = get_term( $option['id'] ); | |
} | |
if ( ! empty( $value ) ) { | |
$classes[] = 'tribe-filter-bar-c-dropdown--has-selection'; | |
} | |
?> | |
<div <?php tribe_classes( $classes ); ?>> | |
<input | |
class="tribe-filter-bar-c-dropdown__input" | |
id="<?php echo esc_attr( $id ); ?>" | |
data-js="tribe-filter-bar-c-dropdown-input" | |
name="<?php echo esc_attr( $name ); ?>" | |
type="hidden" | |
value="<?php echo esc_attr( $value ); ?>" | |
data-allow-html | |
data-dropdown-css-width="false" | |
data-options="<?php echo esc_attr( wp_json_encode( $options ) ); ?>" | |
data-attach-container | |
placeholder="<?php esc_attr_e( 'Select', 'tribe-events-filter-view' ); ?>" | |
style="width: 100%;" <?php /* This is required for selectWoo styling to prevent select box overflow */ ?> | |
/> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment