Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This snippet will add Custom Event Attribute in your Event Search form
- */
- /*
- 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)
- NOTE: Change ContactName with your attribute name
- */
- /************************************/
- function em_ContactName_get_default_search($searches, $array)
- {
- if( !empty($array['ContactName'])){
- $searches['ContactName'] = $array['ContactName'];
- }
- return $searches;
- }
- add_filter('em_events_get_default_search','em_ContactName_get_default_search',1,2);
- add_filter('em_events_get','em_em_ContactName_get_default_search_events_get',1,2);
- function em_em_ContactName_get_default_search_events_get($events, $args)
- {
- if( !empty($args['ContactName'])){
- $event_types = explode(',', $args['ContactName']);
- foreach($events as $event_key => $EM_Event){
- if( !in_array($EM_Event->event_attributes['ContactName'], $event_types) ){
- unset($events[$event_key]);
- }
- }
- }
- return $events;
- }
- function em_contactname_att($args){
- $args['ContactName'] = $_REQUEST['ContactName'];
- return $args;
- }
- add_filter('em_content_events_args','em_contactname_att',1,1);
- /************************************/
- /*
- Step 2: Create this php template and directory in your theme directory:
- 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
- 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:
- */
- /************************************/
- <!-- START Custom Event Attributes -->
- <?php
- //NOTE: Change ContactName with your attribute name
- //NOTE: you might need to modify this to prevent duplicate attribute being added to the options
- ?>
- <?php
- $events = EM_Events::get($args);
- ?>
- <div class="em-search-event-attributes em-search-field">
- <label>Event Attributes </label>
- <select name="ContactName">
- <option> </option>
- <?php foreach($events as $EM_Event){ ?>
- <?php if ( !empty($EM_Event->event_attributes['ContactName']) ): ?>
- <option value="<?php echo $EM_Event->event_attributes['ContactName']; ?>"> <?php echo $EM_Event->event_attributes['ContactName']; ?> </option>
- <?php endif; ?>
- <?php } ?>
- </select>
- </div>
- /************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement