Created
August 21, 2012 13:59
-
-
Save MZAWeb/3415684 to your computer and use it in GitHub Desktop.
Hide events cat from the front end
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 | |
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