Advertisement
BakerMan

tribe_in_category

Sep 27th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. /**
  2.  * Tests to see if the current event is assigned to the specified category or
  3.  * categories.
  4.  *
  5.  * @param $ids int|array
  6.  * @return bool
  7.  */
  8. function tribe_in_category( $ids ) {
  9.     $ids = (array) $ids;
  10.     $categories = get_the_terms( get_the_ID(), TribeEvents::TAXONOMY );
  11.  
  12.     foreach ( $categories as $category )
  13.         if ( in_array( $category->term_id, $ids ) )
  14.             return true;
  15.  
  16.     return false;
  17. }
  18.  
  19. // Conditional test that could be included in ecp-single-template.php
  20. if ( tribe_in_category( 4 ) ) echo 'Go category 4! Yeah!';
  21. else echo 'This category is for losers!';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement