eventsmanager

Location Custom Taxonomy

Feb 22nd, 2013 (edited)
2,457
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 1 0
  1. /* POST CATEGORIES
  2. * USAGE: [locations_list postcategory="4"]
  3. */
  4. add_filter('em_locations_get','my_em_em_locations_get_cats',10,2);
  5. function my_em_em_locations_get_cats($EM_Locations, $args){
  6. if( !empty($args['postcategory']) ){
  7. $search = explode(',',$args['postcategory']);
  8. foreach($EM_Locations as $location_key => $EM_Location){
  9. $terms = array();
  10. $term_array = array();
  11. $terms = get_the_terms( $EM_Location->post_id , 'category' );
  12. if ( is_array($terms) ){
  13. foreach( $terms as $term ) {
  14. if ( !in_array($term->term_id, $search) ){
  15. unset($EM_Locations[$location_key]);
  16. break;
  17. }
  18. }
  19. }else{
  20. unset($EM_Locations[$location_key]);
  21. }
  22. }
  23. }
  24. return $EM_Locations;
  25. }
  26. add_filter('em_locations_get_default_search','my_em_em_locations_get_default_search_cats',1,2);
  27. function my_em_em_locations_get_default_search_cats($searches, $array){
  28. if( !empty($array['postcategory']) ){
  29. $searches['postcategory'] = $array['postcategory'];
  30. }
  31. return $searches;
  32. }
  33. /* POST CATEGORIES */
  34.  
  35. /*
  36. * POST TAGS
  37. * USAGE: [locations_list posttag="4"]
  38. */
  39. add_filter('em_locations_get','my_em_em_locations_get_tag',10,2);
  40. function my_em_em_locations_get_tag($EM_Locations, $args){
  41. if( !empty($args['posttag']) ){
  42. $search = explode(',',$args['posttag']);
  43. foreach($EM_Locations as $location_key => $EM_Location){
  44. $terms = array();
  45. $term_array = array();
  46. $terms = get_the_terms( $EM_Location->post_id , 'post_tag' );
  47. if ( is_array($terms) ){
  48. foreach( $terms as $term ) {
  49. if ( !in_array($term->term_id, $search) ){
  50. unset($EM_Locations[$location_key]);
  51. break;
  52. }
  53. }
  54. }else{
  55. unset($EM_Locations[$location_key]);
  56. }
  57. }
  58. }
  59. return $EM_Locations;
  60. }
  61. add_filter('em_locations_get_default_search','my_em_em_locations_get_default_search_tag',1,2);
  62. function my_em_em_locations_get_default_search_tag($searches, $array){
  63. if( !empty($array['posttag']) ){
  64. $searches['posttag'] = $array['posttag'];
  65. }
  66. return $searches;
  67. }
  68. /* POST TAGS */
  69.  
  70.  
  71. function my_em_own_taxonomy_register(){
  72. register_taxonomy_for_object_type('category',EM_POST_TYPE_LOCATION);
  73. register_taxonomy_for_object_type('post_tag',EM_POST_TYPE_LOCATION);
  74. }
  75. add_action('init','my_em_own_taxonomy_register',100);
Add Comment
Please, Sign In to add comment