Created
February 27, 2021 03:32
-
-
Save joshfeck/79e5e64826f1c769f557b5670c979217 to your computer and use it in GitHub Desktop.
Exclude events from event lists using a tag. In this example, any events with the tag "exclude" will not be included in front end event lists. Event Espresso 4.
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 // only add this opening PHP tag if starting with a new file with no opening PHP tag | |
add_filter( 'posts_where', 'ee_remove_hidden_tagged_event_list', 25, 2 ); | |
function ee_remove_hidden_tagged_event_list( $SQL, WP_Query $wp_query ) { | |
global $wpdb; | |
$tag = get_term_by( 'slug', 'exclude', 'post_tag' ); | |
if( $tag instanceof WP_Term ) { | |
$tag_id = $tag->term_id; | |
} else { | |
return $SQL; | |
} | |
if ( | |
isset( $wp_query->query_vars['post_type'] ) && | |
( $wp_query->query_vars['post_type'] == 'espresso_events' || | |
( is_array( $wp_query->query_vars['post_type'] ) && | |
in_array( 'espresso_events', $wp_query->query_vars['post_type'] ) ) ) && | |
! $wp_query->is_singular ) { | |
$SQL .= " AND ID NOT IN (SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id={$tag_id} )"; // change to hidden tag ID | |
} | |
return $SQL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment