Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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
- */
- $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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement