Created
March 17, 2020 21:47
-
-
Save barryhughes/80423ba03c37d033e68aa52e8192daec to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Remove events tagged with any of the slugs listed below from | |
* event views. | |
* | |
* We deliberately avoid use of TEC functions and constants etc | |
* so that this doesn't break should that plugin temporarily be | |
* deactivated. | |
*/ | |
add_filter( 'pre_get_posts', function( $query ) { | |
if ( | |
$query->get( 'post_type' ) !== 'tribe_events' | |
|| ! $query->is_archive() | |
) { | |
return; | |
} | |
// Add slugs of tags you wish to ignore here! | |
$tags = [ | |
'ignore', | |
'hidden', | |
'missing', | |
# add more slugs here | |
]; | |
// Let's convert them to tag IDs | |
foreach ( $tags as $index => $tag ) { | |
$term = get_term_by( 'slug', $tag, 'post_tag' ); | |
if ( is_a( $term, 'WP_Term' ) ) { | |
$tags[$index] = $term->term_id; | |
} | |
else { | |
unset( $tags[$index] ); | |
} | |
} | |
// No tag IDs? No need to do anything :-) | |
if ( empty( $tags ) ) { | |
return; | |
} | |
// Grab any existing tag IDs we should ignore and combine with our additional IDs. | |
$ignore_tags = (array) $query->get( 'tag__not_in' ); | |
$ignore_tags = array_unique( array_merge( $ignore_tags, $tags ) ); | |
// Update the query. | |
$query->set( 'tag__not_in', $ignore_tags ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment