Skip to content

Instantly share code, notes, and snippets.

@MZAWeb
Created August 21, 2012 13:59
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 MZAWeb/3415684 to your computer and use it in GitHub Desktop.
Save MZAWeb/3415684 to your computer and use it in GitHub Desktop.
Hide events cat from the front end
<?php
add_filter( 'parse_tribe_event_query', 'hide_my_private_category', 999 );
function hide_my_private_category( $query ) {
/*
* First we create the tax_query for excluding
* all the events that have the term 'hidden'.
* Change that 'hidden' for the slug of the term
* you want to hide from the Front End.
*
*/
$taxquery = array( 'taxonomy' => TribeEvents::TAXONOMY,
'field' => 'slug',
'terms' => array( 'hidden' ),
'operator' => 'NOT IN' );
/*
* The we merge our new tax_query with the
* original one, so we don't loose any category
* filter we may need to use in the Front End
*/
$taxquery = array_merge( $taxquery, $query->tax_query->queries );
/*
* And at the end we add the new resulting tax_query
* to the main events query, _before_ said query
* so we don't need to traverse the whole results
* and delete the events we don't want to show.
*
* This is the equivalent of using pre_get_posts
* to filter things out in the standard WordPress
* way
*
*/
$query->set( 'tax_query', array( $taxquery ) );
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment