Last active
May 17, 2016 21:05
-
-
Save mtio/486d9d53cbeaee13473c8c2da8f8cc52 to your computer and use it in GitHub Desktop.
Registering taxonomies with wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function register_taxonomies() | |
| { | |
| $tags = [ | |
| 'performer' => [ | |
| 'name' => _x( 'Performers', 'taxonomy general name' ), | |
| 'singular_name' => _x( 'Performer', 'taxonomy singular name' ), | |
| 'search_items' => __( 'Search Performers' ), | |
| 'all_items' => __( 'All Performers' ), | |
| 'parent_item' => null, | |
| 'parent_item_colon' => null | |
| ], | |
| 'city' => [ | |
| 'name' => _x( 'Cities', 'taxonomy general name' ), | |
| 'singular_name' => _x( 'City', 'taxonomy singular name' ), | |
| 'search_items' => __( 'Search Cities' ), | |
| 'all_items' => __( 'All Cities' ), | |
| 'parent_item' => null, | |
| 'parent_item_colon' => null | |
| ], | |
| 'event-type' => [ | |
| 'args' => [ | |
| 'hierarchical' => false, | |
| 'show_ui' => true, | |
| 'show_admin_column' => true | |
| ], | |
| 'name' => _x( 'Event Types', 'taxonomy general name' ), | |
| 'singular_name' => _x( 'Event Type', 'taxonomy singular name' ), | |
| 'search_items' => __( 'Search Event Types' ), | |
| 'all_items' => __( 'All Event Types' ), | |
| 'parent_item' => null, | |
| 'parent_item_colon' => null | |
| ], | |
| 'venue' => [ | |
| 'name' => _x( 'Venues', 'taxonomy general name' ), | |
| 'singular_name' => _x( 'Venue', 'taxonomy singular name' ), | |
| 'search_items' => __( 'Search Venues' ), | |
| 'all_items' => __( 'All Venues' ), | |
| 'parent_item' => null, | |
| 'parent_item_colon' => null, | |
| ] | |
| ]; | |
| $categories = [ | |
| 'parent' => [ | |
| 'name' => _x( 'Parent Categories', 'taxonomy general name' ), | |
| 'singular_name' => _x( 'Parent Category', 'taxonomy singular name' ), | |
| 'search_items' => __( 'Search Parent Category' ), | |
| 'all_items' => __( 'All Parent Categories' ), | |
| 'parent_item' => null, | |
| 'parent_item_colon' => null | |
| ], | |
| 'child' => [ | |
| 'name' => _x( 'Child Categories', 'taxonomy general name' ), | |
| 'singular_name' => _x( 'Child Category', 'taxonomy singular name' ), | |
| 'search_items' => __( 'Search Child Category' ), | |
| 'all_items' => __( 'All Child Categories' ), | |
| 'parent_item' => __( 'Parent Categories' ), | |
| 'parent_item_colon' => __( 'Parent Categories:' ) | |
| ], | |
| 'grandChild' => [ | |
| 'name' => _x( 'Grandchild Categories', 'taxonomy general name' ), | |
| 'singular_name' => _x( 'Grandchild Category', 'taxonomy singular name' ), | |
| 'search_items' => __( 'Search Grandchild Category' ), | |
| 'all_items' => __( 'All Grandchild Categories' ), | |
| 'parent_item' => __( 'Parent Categories' ), | |
| 'parent_item_colon' => __( 'Parent Categories:' ) | |
| ] | |
| ]; | |
| foreach ($tags as $tag) { | |
| if (array_key_exists('args', $tag)) { | |
| $args = $tag['args']; | |
| unset($tag['args']); | |
| $args['labels'] = $tag; | |
| } else { | |
| $args = [ | |
| 'hierarchical' => false, | |
| 'labels' => $tag, | |
| 'show_ui' => true | |
| ]; | |
| } | |
| $name = $tag['singular_name']; | |
| $name = str_replace(' ', '_', strtolower($name)); | |
| register_taxonomy($name, 'event_post', $args); | |
| } | |
| foreach ($categories as $category) { | |
| $args = [ | |
| 'hierarchical' => true, | |
| 'labels' => $category, | |
| 'show_ui' => true | |
| ]; | |
| $name = $category['singular_name']; | |
| $name = str_replace(' ', '_', strtolower($name)); | |
| register_taxonomy($name, 'event_post', $args); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment