Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- This snippet will create a custom taxonomy, register it to the event CPT, and add a search field to your events search form.
- By Events Manager 5.5.8 the last two functions aren't needed, because EM will automatically register these new taxonomies as searchable within itself.
- For help with adding this for your site, see here - http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
- */
- //Create a custom taxonomy.
- function my_em_create_custom_taxonomy() {
- $labels = array(
- 'name' => 'Grades',
- 'singular_name' => 'Grade',
- 'search_items' => 'Search Grades',
- 'all_items' => 'All Grades',
- 'parent_item' => 'Parent Grade',
- 'parent_item_colon' => 'Parent Grade:',
- 'edit_item' => 'Edit Grade',
- 'update_item' => 'Update Grade',
- 'add_new_item' => 'Add New Grade',
- 'new_item_name' => 'New Grade Name',
- 'menu_name' => 'Grade Categories',
- );
- register_taxonomy('grades',array(EM_POST_TYPE_EVENT), array(
- 'hierarchical' => true,
- 'labels' => $labels,
- 'query_var' => true
- ));
- }
- add_action( 'init', 'my_em_create_custom_taxonomy', 0 );
- //Hook into the search form and add the Custom Taxonomy search field.
- function my_em_custom_taxonomy_search_form(){
- ?>
- <div class="em-search-category em-search-field">
- <label>Grades</label>
- <?php
- $selected = !empty($_REQUEST['grades']) ? $_REQUEST['grades']:false;
- wp_dropdown_categories( array(
- 'hide_empty' => 0,
- 'orderby' =>'name',
- 'name' => 'grades',
- 'hierarchical' => true,
- 'taxonomy' => 'grades',
- 'selected' => $selected,
- 'show_option_none' => 'Choose a grade',
- 'option_none_value'=>0,
- 'class'=>'em-events-search-grade',
- ));
- ?>
- </div>
- <?php
- }
- add_action('em_template_events_search_form_footer', 'my_em_custom_taxonomy_search_form');
- //Delete everthing below in Events Manager 5.5.8 or later, although this has no negative impact if left here by mistake
- function my_em_custom_taxonomy_accepted_search($searches){
- $searches[] = 'grades';
- return $searches;
- }
- add_filter('em_accepted_searches','my_em_custom_taxonomy_accepted_search',1,1);
- function my_em_custom_taxonomy_default_search( $args ){
- if( empty($args['grades']) ) $args['grades'] = false;
- return $args;
- }
- add_filter('em_events_get_default_search','my_em_custom_taxonomy_default_search');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement