Skip to content

Instantly share code, notes, and snippets.

@MZAWeb
Created September 4, 2012 20:15
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/3625950 to your computer and use it in GitHub Desktop.
Save MZAWeb/3625950 to your computer and use it in GitHub Desktop.
2nd pass at hidden category
<?php
/*
Plugin Name: Private Events
Plugin URI: http://tri.be
Description: This plugin allows you to have a private event category only visible to viewers who have logged in to your site.
Version: 1.0
Author: Daniel - Coder / Phil - Plugin typer upper
Author URI: http://tri.be
License: A "Slug" license name e.g. GPL2
*/
?>
<?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( 'private' ),
'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
*/
if ( $query->tax_query && property_exists( $query->tax_query, 'queries' ) ) {
$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