Advertisement
Guest User

Untitled

a guest
Sep 4th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Private Events
  4. Plugin URI: http://tri.be
  5. Description: This plugin allows you to have a private event category only visible to viewers who have logged in to your site.
  6. Version: 1.0
  7. Author: Daniel - Coder / Phil - Plugin typer upper
  8. Author URI: http://tri.be
  9. License: A "Slug" license name e.g. GPL2
  10. */
  11. ?>
  12. <?php
  13. add_filter( 'parse_tribe_event_query', 'hide_my_private_category', 999 );
  14.  
  15. function hide_my_private_category( $query ) {
  16.  
  17. /*
  18. * First we create the tax_query for excluding
  19. * all the events that have the term 'hidden'.
  20. * Change that 'hidden' for the slug of the term
  21. * you want to hide from the Front End.
  22. *
  23. */
  24. $taxquery = array( 'taxonomy' => TribeEvents::TAXONOMY,
  25. 'field' => 'slug',
  26. 'terms' => array( 'private' ),
  27. 'operator' => 'NOT IN' );
  28.  
  29. /*
  30. * The we merge our new tax_query with the
  31. * original one, so we don't loose any category
  32. * filter we may need to use in the Front End
  33. */
  34.  
  35. $taxquery = array_merge( $taxquery, $query->tax_query->queries );
  36.  
  37. /*
  38. * And at the end we add the new resulting tax_query
  39. * to the main events query, _before_ said query
  40. * so we don't need to traverse the whole results
  41. * and delete the events we don't want to show.
  42. *
  43. * This is the equivalent of using pre_get_posts
  44. * to filter things out in the standard WordPress
  45. * way
  46. *
  47. */
  48.  
  49. $query->set( 'tax_query', array( $taxquery ) );
  50.  
  51.  
  52. return $query;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement