namespace IndrukwekkendReferenties; class Taxonomy { public function __construct() { // Registreer taxonomie iets later, zodat CPT al bestaat \add_action( 'init', [ $this, 'call_wp_add_taxonomy' ], 12 ); \add_action( 'init', [ $this, 'attach_tax_to_cpt' ], 13 ); $this->add_acf_fields(); } public function call_wp_add_taxonomy() { $cpts = array( 'reference' ); $this->wp_add_taxonomy( 'reference_category', 'en', $cpts ); } // Zorg dat de taxonomie sowieso aan het CPT hangt, ook als volgorde wisselt public function attach_tax_to_cpt() { \register_taxonomy_for_object_type( 'reference_category', 'reference' ); } public function wp_add_taxonomy( $tax, $sen = 's', $cpts = array(), $show_in_column = true ) { $tax = strtolower( $tax ); $enkelvoud = 'Categorie'; $meervoud = 'Categorieen'; $labels = array( 'name' => _x( $meervoud, 'taxonomy general name' ), 'singular_name' => _x( $enkelvoud, 'taxonomy singular name' ), 'search_items' => __( 'Zoek ' . $meervoud ), 'all_items' => __( 'Alle ' . $meervoud ), 'parent_item' => __( 'Hoofd ' . $enkelvoud ), 'parent_item_colon' => __( 'Hoofd (' . $enkelvoud . ') niveau:' ), 'edit_item' => __( 'Pas (' . $enkelvoud . ') niveau aan' ), 'update_item' => __( 'Update ' . $enkelvoud ), 'add_new_item' => __( 'Voeg nieuw ' . $enkelvoud . ' toe' ), 'new_item_name' => __( 'Nieuwe ' . $enkelvoud . ' Naam' ), 'menu_name' => $meervoud, ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => $show_in_column, 'show_in_rest' => true, 'query_var' => true, 'rewrite' => array( 'slug' => $tax ), ); \register_taxonomy( $tax, $cpts, $args ); } private function add_acf_fields() { if ( function_exists( 'acf_add_local_field_group' ) ) : acf_add_local_field_group( array( 'key' => 'group_reference_category_values', 'title' => 'Waarden', 'fields' => array( array( 'key' => 'field_reference_category_value', 'label' => 'value', 'name' => 'value', 'type' => 'number', ), ), 'location' => array( array( array( 'param' => 'taxonomy', 'operator' => '==', 'value' => 'reference_category', // <-- juist targetten ), ), ), ) ); endif; } } namespace IndrukwekkendReferenties; class Taxonomy { public function __construct() { // Registreer taxonomie iets later, zodat CPT al bestaat \add_action( 'init', [ $this, 'call_wp_add_taxonomy' ], 12 ); \add_action( 'init', [ $this, 'attach_tax_to_cpt' ], 13 ); $this->add_acf_fields(); } public function call_wp_add_taxonomy() { $cpts = array( 'reference' ); $this->wp_add_taxonomy( 'reference_category', 'en', $cpts ); } // Zorg dat de taxonomie sowieso aan het CPT hangt, ook als volgorde wisselt public function attach_tax_to_cpt() { \register_taxonomy_for_object_type( 'reference_category', 'reference' ); } public function wp_add_taxonomy( $tax, $sen = 's', $cpts = array(), $show_in_column = true ) { $tax = strtolower( $tax ); $enkelvoud = 'Categorie'; $meervoud = 'Categorieen'; $labels = array( 'name' => _x( $meervoud, 'taxonomy general name' ), 'singular_name' => _x( $enkelvoud, 'taxonomy singular name' ), 'search_items' => __( 'Zoek ' . $meervoud ), 'all_items' => __( 'Alle ' . $meervoud ), 'parent_item' => __( 'Hoofd ' . $enkelvoud ), 'parent_item_colon' => __( 'Hoofd (' . $enkelvoud . ') niveau:' ), 'edit_item' => __( 'Pas (' . $enkelvoud . ') niveau aan' ), 'update_item' => __( 'Update ' . $enkelvoud ), 'add_new_item' => __( 'Voeg nieuw ' . $enkelvoud . ' toe' ), 'new_item_name' => __( 'Nieuwe ' . $enkelvoud . ' Naam' ), 'menu_name' => $meervoud, ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => $show_in_column, 'show_in_rest' => true, 'query_var' => true, 'rewrite' => array( 'slug' => $tax ), ); \register_taxonomy( $tax, $cpts, $args ); } private function add_acf_fields() { if ( function_exists( 'acf_add_local_field_group' ) ) : acf_add_local_field_group( array( 'key' => 'group_reference_category_values', 'title' => 'Waarden', 'fields' => array( array( 'key' => 'field_reference_category_value', 'label' => 'value', 'name' => 'value', 'type' => 'number', ), ), 'location' => array( array( array( 'param' => 'taxonomy', 'operator' => '==', 'value' => 'reference_category', // <-- juist targetten ), ), ), ) ); endif; } }