Last active
October 5, 2023 23:05
-
-
Save lelandf/a8c12ee073c4919815c7320a315d14c9 to your computer and use it in GitHub Desktop.
[TEC] Template override to get rid of unwanted filter bar categories
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 */ | |
// 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