Can you try to use CPT UI instead of manual code?
Everything works for me.
I have taxonomy term external
:
https://demo.kubiq.sk/product_type/external/
and here is my product post:
https://demo.kubiq.sk/external/xxx/
These are my Permalinks settings:
https://i.imgur.com/FPtfa9P.png
Here is code export from CPT UI:
function cptui_register_my_cpts_product() {
/**
* Post Type: Products.
*/
$labels = [
"name" => esc_html__( "Products", "twentytwentythree" ),
"singular_name" => esc_html__( "Product", "twentytwentythree" ),
"menu_name" => esc_html__( "Products", "twentytwentythree" ),
"all_items" => esc_html__( "All Products", "twentytwentythree" ),
"add_new" => esc_html__( "Add new", "twentytwentythree" ),
"add_new_item" => esc_html__( "Add new Product", "twentytwentythree" ),
"edit_item" => esc_html__( "Edit Product", "twentytwentythree" ),
"new_item" => esc_html__( "New Product", "twentytwentythree" ),
"view_item" => esc_html__( "View Product", "twentytwentythree" ),
"view_items" => esc_html__( "View Products", "twentytwentythree" ),
"search_items" => esc_html__( "Search Products", "twentytwentythree" ),
"not_found" => esc_html__( "No Products found", "twentytwentythree" ),
"not_found_in_trash" => esc_html__( "No Products found in trash", "twentytwentythree" ),
"parent" => esc_html__( "Parent Product:", "twentytwentythree" ),
"featured_image" => esc_html__( "Featured image for this Product", "twentytwentythree" ),
"set_featured_image" => esc_html__( "Set featured image for this Product", "twentytwentythree" ),
"remove_featured_image" => esc_html__( "Remove featured image for this Product", "twentytwentythree" ),
"use_featured_image" => esc_html__( "Use as featured image for this Product", "twentytwentythree" ),
"archives" => esc_html__( "Product archives", "twentytwentythree" ),
"insert_into_item" => esc_html__( "Insert into Product", "twentytwentythree" ),
"uploaded_to_this_item" => esc_html__( "Upload to this Product", "twentytwentythree" ),
"filter_items_list" => esc_html__( "Filter Products list", "twentytwentythree" ),
"items_list_navigation" => esc_html__( "Products list navigation", "twentytwentythree" ),
"items_list" => esc_html__( "Products list", "twentytwentythree" ),
"attributes" => esc_html__( "Products attributes", "twentytwentythree" ),
"name_admin_bar" => esc_html__( "Product", "twentytwentythree" ),
"item_published" => esc_html__( "Product published", "twentytwentythree" ),
"item_published_privately" => esc_html__( "Product published privately.", "twentytwentythree" ),
"item_reverted_to_draft" => esc_html__( "Product reverted to draft.", "twentytwentythree" ),
"item_scheduled" => esc_html__( "Product scheduled", "twentytwentythree" ),
"item_updated" => esc_html__( "Product updated.", "twentytwentythree" ),
"parent_item_colon" => esc_html__( "Parent Product:", "twentytwentythree" ),
];
$args = [
"label" => esc_html__( "Products", "twentytwentythree" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => true,
"rest_base" => "",
"rest_controller_class" => "WP_REST_Posts_Controller",
"rest_namespace" => "wp/v2",
"has_archive" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"delete_with_user" => false,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"can_export" => false,
"rewrite" => [ "slug" => "product", "with_front" => true ],
"query_var" => true,
"supports" => [ "title", "editor", "thumbnail", "excerpt", "custom-fields" ],
"show_in_graphql" => false,
];
register_post_type( "product", $args );
}
add_action( 'init', 'cptui_register_my_cpts_product' );
function cptui_register_my_taxes_product_type() {
/**
* Taxonomy: Product Types.
*/
$labels = [
"name" => esc_html__( "Product Types", "twentytwentythree" ),
"singular_name" => esc_html__( "Product Type", "twentytwentythree" ),
"menu_name" => esc_html__( "Product Types", "twentytwentythree" ),
"all_items" => esc_html__( "All Product Types", "twentytwentythree" ),
"edit_item" => esc_html__( "Edit Product Type", "twentytwentythree" ),
"view_item" => esc_html__( "View Product Type", "twentytwentythree" ),
"update_item" => esc_html__( "Update Product Type name", "twentytwentythree" ),
"add_new_item" => esc_html__( "Add new Product Type", "twentytwentythree" ),
"new_item_name" => esc_html__( "New Product Type name", "twentytwentythree" ),
"parent_item" => esc_html__( "Parent Product Type", "twentytwentythree" ),
"parent_item_colon" => esc_html__( "Parent Product Type:", "twentytwentythree" ),
"search_items" => esc_html__( "Search Product Types", "twentytwentythree" ),
"popular_items" => esc_html__( "Popular Product Types", "twentytwentythree" ),
"separate_items_with_commas" => esc_html__( "Separate Product Types with commas", "twentytwentythree" ),
"add_or_remove_items" => esc_html__( "Add or remove Product Types", "twentytwentythree" ),
"choose_from_most_used" => esc_html__( "Choose from the most used Product Types", "twentytwentythree" ),
"not_found" => esc_html__( "No Product Types found", "twentytwentythree" ),
"no_terms" => esc_html__( "No Product Types", "twentytwentythree" ),
"items_list_navigation" => esc_html__( "Product Types list navigation", "twentytwentythree" ),
"items_list" => esc_html__( "Product Types list", "twentytwentythree" ),
"back_to_items" => esc_html__( "Back to Product Types", "twentytwentythree" ),
"name_field_description" => esc_html__( "The name is how it appears on your site.", "twentytwentythree" ),
"parent_field_description" => esc_html__( "Assign a parent term to create a hierarchy. The term Jazz, for example, would be the parent of Bebop and Big Band.", "twentytwentythree" ),
"slug_field_description" => esc_html__( "The slug is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.", "twentytwentythree" ),
"desc_field_description" => esc_html__( "The description is not prominent by default; however, some themes may show it.", "twentytwentythree" ),
];
$args = [
"label" => esc_html__( "Product Types", "twentytwentythree" ),
"labels" => $labels,
"public" => true,
"publicly_queryable" => true,
"hierarchical" => true,
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => [ 'slug' => 'product_type', 'with_front' => true, ],
"show_admin_column" => false,
"show_in_rest" => true,
"show_tagcloud" => false,
"rest_base" => "product_type",
"rest_controller_class" => "WP_REST_Terms_Controller",
"rest_namespace" => "wp/v2",
"show_in_quick_edit" => false,
"sort" => false,
"show_in_graphql" => false,
];
register_taxonomy( "product_type", [ "product" ], $args );
}
add_action( 'init', 'cptui_register_my_taxes_product_type' );