add_action( 'init', 'create_taxonomy' );
function create_taxonomy(){
register_taxonomy('genre', ['projects'], array(
'hierarchical' => false,
'labels' => array(
'name' => _x( 'Genres', 'taxonomy general name' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
'search_items' => __( 'Search Genres' ),
'all_items' => __( 'All Genres' ),
'parent_item' => __( 'Parent Genre' ),
'parent_item_colon' => __( 'Parent Genre:' ),
'edit_item' => __( 'Edit Genre' ),
'update_item' => __( 'Update Genre' ),
'add_new_item' => __( 'Add New Genre' ),
'new_item_name' => __( 'New Genre Name' ),
'menu_name' => __( 'Genre' ),
),
'public' => true,
'show_ui' => true,
'query_var' => true,
));
}
add_action( 'init', 'create_taxonomy' );
function generation_taxonomy() {
$catalog_genres = get_terms( [
'taxonomy' => 'genre',
'hide_empty' => false,
] );
foreach( $catalog_genres as $genre ){
register_taxonomy( 'pj_' . $genre->slug, ['projects'], array(
'hierarchical' => false,
'labels' => array(
'name' => $genre->name,
'singular_name' => $genre->name,
'search_items' => __( 'Search Genres' ),
'all_items' => __( 'All Genres' ),
'parent_item' => __( 'Parent Genre' ),
'parent_item_colon' => __( 'Parent Genre:' ),
'edit_item' => __( 'Edit Genre' ),
'update_item' => __( 'Update Genre' ),
'add_new_item' => __( 'Add New Genre' ),
'new_item_name' => __( 'New Genre Name' ),
'menu_name' => $genre->name,
),
'public' => true,
'show_ui' => true,
'query_var' => true,
));
var_dump($genre);
}
}
add_action( 'init', 'generation_taxonomy' );