Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Created May 17, 2013 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenharris/5600396 to your computer and use it in GitHub Desktop.
Save stephenharris/5600396 to your computer and use it in GitHub Desktop.
Excludes specified event categories from any event query. Untested.
<?php
/**
* Excludes specified event categories from any event query. Untested.
*/
add_action( 'pre_get_posts','harris_exclude_event_terms' );
function harris_exclude_event_terms( $query ) {
if ( $query->is_main_query() && eventorganiser_is_event_query( $query ) ) {
$tax_query = $query->get( 'tax_query' );
$tax_query['relation'] = 'AND';
$tax_query[] = array(
'taxonomy' => 'event-category',
'field' => 'id',
'terms' => array( 'my-slug', 'my-other-slug' ),
'operator' => 'NOT IN'
);
$query->set( 'tax_query', $tax_query );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment