@@ -37,8 +37,13 @@ public function __construct() {
3737 $ this ->labels = $ this ->labels ();
3838 $ this ->args = $ this ->args ( $ this ->labels );
3939
40+ $ this ->taxonomy_labels = $ this ->taxonomy_labels ();
41+ $ this ->taxonomy_args = $ this ->taxonomy_args ( $ this ->taxonomy_labels );
42+
4043 //register_post_type( 'cpt_name', $this->args );
4144 //add_filter( 'post_updated_messages', array( $this, 'group_updated_messages' ) );
45+
46+ //register_taxonomy( 'custom_tax', array( 'cpt_name' ), $this->taxonomy_args );
4247 }
4348
4449
@@ -70,7 +75,7 @@ public function labels() {
7075
7176
7277 /**
73- * Define the arguments
78+ * Define the arguments for custom post type
7479 *
7580 * @param Array $labels
7681 *
@@ -83,7 +88,7 @@ public function args( $labels ) {
8388 'description ' => __ ( '' , 'textdomain ' ),
8489 'labels ' => $ labels ,
8590 'supports ' => array ( 'title ' , 'editor ' , 'thumbnail ' ),
86- 'taxonomies ' => array ( 'topics ' , 'post_tag ' ),
91+ 'taxonomies ' => array ( 'custom_tax ' , 'post_tag ' ),
8792 'hierarchical ' => true ,
8893 'public ' => true ,
8994 'rewrite ' => array ( 'slug ' => 'slug_name ' ),
@@ -100,7 +105,7 @@ public function args( $labels ) {
100105 'capability_type ' => 'post ' ,
101106 'show_in_rest ' => true ,
102107 //Controls WP REST API behaviour
103- 'rest_controller_class ' => 'WP_REST_Terms_Controller ' ,
108+ 'rest_controller_class ' => 'WP_REST_Posts_Controller ' ,
104109 );
105110
106111 return $ args ;
@@ -134,5 +139,56 @@ public function cpt_updated_messages( $messages ) {
134139
135140 return $ messages ;
136141 }
142+
143+
144+ /**
145+ * Taxonomy labels
146+ *
147+ * @return Array
148+ */
149+ public function taxonomy_labels () {
150+
151+ $ labels = array (
152+ 'name ' => _x ( 'Taxonomy ' , 'taxonomy general name ' , 'textdomain ' ),
153+ 'singular_name ' => _x ( 'Taxonomy ' , 'taxonomy singular name ' , 'textdomain ' ),
154+ 'search_items ' => __ ( 'Search Taxonomy ' , 'textdomain ' ),
155+ 'all_items ' => __ ( 'All Taxonomies ' , 'textdomain ' ),
156+ 'parent_item ' => __ ( 'Parent Taxonomy ' , 'textdomain ' ),
157+ 'parent_item_colon ' => __ ( 'Parent Taxonomy: ' , 'textdomain ' ),
158+ 'edit_item ' => __ ( 'Edit Taxonomy ' , 'textdomain ' ),
159+ 'update_item ' => __ ( 'Update Taxonomy ' , 'textdomain ' ),
160+ 'add_new_item ' => __ ( 'Add New Taxonomy ' , 'textdomain ' ),
161+ 'new_item_name ' => __ ( 'New Taxonomy Name ' , 'textdomain ' ),
162+ 'menu_name ' => __ ( 'Taxonomy ' , 'textdomain ' ),
163+ );
164+
165+ return $ labels ;
166+ }
167+
168+
169+ /**
170+ * Define the arguments for custom taxonomy
171+ *
172+ * @param Array $labels
173+ *
174+ * @return Array
175+ */
176+ public function taxonomy_args ( $ labels ) {
177+
178+ $ args = array (
179+ 'hierarchical ' => true ,
180+ 'labels ' => $ labels ,
181+ 'show_ui ' => true ,
182+ 'show_admin_column ' => true ,
183+ 'query_var ' => true ,
184+ 'rewrite ' => array ( 'slug ' => 'custom_tax ' ),
185+ 'show_in_rest ' => true ,
186+ 'rest_base ' => 'custom_tax ' ,
187+ //Controls WP REST API behaviour
188+ 'rest_controller_class ' => 'WP_REST_Terms_Controller ' ,
189+ );
190+
191+ return $ args ;
192+ }
137193 }
138194}
0 commit comments