eventsmanager

Add Custom Event Attribute in your Event Search form

Feb 25th, 2016
492
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This snippet will add Custom Event Attribute in your Event Search form
  3. */
  4.  
  5. /*
  6. Step 1: add this custom filters in your theme functions.php or thru wp-content/mu-plugins/functions.php(create this php file or directory if this does not exists yet)
  7.  
  8. NOTE: Change ContactName with your attribute name
  9. */
  10.  
  11. /************************************/
  12.  
  13. function em_ContactName_get_default_search($searches, $array)
  14. {
  15. if( !empty($array['ContactName'])){
  16. $searches['ContactName'] = $array['ContactName'];
  17. }
  18. return $searches;
  19. }
  20. add_filter('em_events_get_default_search','em_ContactName_get_default_search',1,2);
  21.  
  22. add_filter('em_events_get','em_em_ContactName_get_default_search_events_get',1,2);
  23. function em_em_ContactName_get_default_search_events_get($events, $args)
  24. {
  25. if( !empty($args['ContactName'])){
  26.  
  27. $event_types = explode(',', $args['ContactName']);
  28. foreach($events as $event_key => $EM_Event){
  29. if( !in_array($EM_Event->event_attributes['ContactName'], $event_types) ){
  30. unset($events[$event_key]);
  31. }
  32. }
  33. }
  34. return $events;
  35. }
  36.  
  37. function em_contactname_att($args){
  38. $args['ContactName'] = $_REQUEST['ContactName'];
  39. return $args;
  40. }
  41. add_filter('em_content_events_args','em_contactname_att',1,1);
  42.  
  43. /************************************/
  44.  
  45. /*
  46. Step 2: Create this php template and directory in your theme directory:
  47.  
  48. wp-contents > Themes > Your Theme Name > (create this folder) plugins > (create this folder) events-manager > (create this folder) templates > (create this folder) search > (create this file) categories.php
  49.  
  50. THEN edit this categories.php THEN copy the contents from wp-content/plugins/events-manager/templates/templates/search/categories.php and (add at the bottom) paste the following:
  51. */
  52.  
  53. /************************************/
  54. <!-- START Custom Event Attributes -->
  55. <?php
  56. //NOTE: Change ContactName with your attribute name
  57. //NOTE: you might need to modify this to prevent duplicate attribute being added to the options
  58. ?>
  59. <?php
  60. $events = EM_Events::get($args);
  61. ?>
  62. <div class="em-search-event-attributes em-search-field">
  63. <label>Event Attributes </label>
  64. <select name="ContactName">
  65. <option> </option>
  66. <?php foreach($events as $EM_Event){ ?>
  67. <?php if ( !empty($EM_Event->event_attributes['ContactName']) ): ?>
  68. <option value="<?php echo $EM_Event->event_attributes['ContactName']; ?>"> <?php echo $EM_Event->event_attributes['ContactName']; ?> </option>
  69. <?php endif; ?>
  70. <?php } ?>
  71. </select>
  72. </div>
  73. /************************************/
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×