[Plugin: Events Manager] Searching by custom taxonomy
-
I created a custom taxonomy, which works perfectly. Now I just need to figure out how to make it searchable. I followed the instructions on the Events Manager page https://wp-events-plugin.com/tutorials/creating-a-events-manager-add-on-a-complete-walkthrough/ by following step 6 and 7. It creates a dropdown but none of the artist names show up
Here is the code I used
// custom Artist taxonomy for events add_action( 'init', 'register_my_taxonomies', 0 ); function register_my_taxonomies() { $labels = array( 'name' => 'Artists', 'singular_name' => 'Artist', 'search_items' => 'Search Artists', 'popular_items' => 'Popular Artists', 'all_items' => 'All Artists', 'parent_item' => 'Parent Artist', 'edit_item' => 'Edit Artist', 'update_item' => 'Update Artist', 'add_new_item' => 'Add New Artist', 'new_item_name' => 'New Artist', 'separate_items_with_commas' => 'Separate Artists with commas', 'add_or_remove_items' => 'Add or remove Artists', 'choose_from_most_used' => 'Choose from most used Artists' ); $args = array( 'label' => 'Artists', 'labels' => $labels, 'public' => true, 'hierarchical' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'args' => array( 'orderby' => 'term_order' ), 'rewrite' => array( 'slug' => 'events/artists', 'with_front' => false ), 'query_var' => true ); register_taxonomy( 'artists', EM_POST_TYPE_EVENT, $args ); } // custom taxonomy search and display add_filter('em_events_get_default_search','artists_get_default_search',1,2); function artists_get_default_search($searches, $array){ if( !empty($array['artist']) && is_numeric($array['artist']) ){ $searches['artist'] = $array['artist']; } return $searches; } add_filter('em_events_get','artists_events_get',1,2); function artists_events_get($events, $args){ if( !empty($args['artist']) && is_numeric($args['artist']) ){ foreach($events as $event_key => $EM_Event){ if( !in_array($args['artist'],$EM_Event->artists) ){ unset($events[$event_key]); } } } return $events; } add_action('em_template_events_search_form_ddm', 'artists_search_form'); function artists_search_form(){ $artists = (is_array(get_option('Artists'))) ? get_option('Artists'):array(); ?> <!-- START Styles Search --> <select name="artist"> <option value=''>Artists</option> <?php foreach($artists as $artist_id=>$artist_name): ?> <option value="<?php echo $artist_id; ?>" <?php echo ($_POST['artist'] == $artist_id) ? 'selected="selected"':''; ?>><?php echo $artist_name; ?></option> <?php endforeach; ?> </select> <!-- END Styles Search --> <?php } function artists_accepted_searches($searches){ $searches[] = 'artist'; return $searches; } add_filter('em_accepted_searches','artists_accepted_searches',1,1);
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘[Plugin: Events Manager] Searching by custom taxonomy’ is closed to new replies.