Site icon Hip-Hop Website Design and Development

Rewriting url for multiple Taxonomies and CPT

I have 2 taxonomies ("product_type" and "brand") and Custom Post Type ("product").

Taxonomy "product_type"
Terms: "home line" and "traditional machines"
https://domain.com/?product_type=home-line and https://domain.com/?product_type=traditional-machines

Taxonomy "brand"
Term: "company"
https://domain.com/brands/rancilio/

The url structure I want to get is

It’s giving me 404 error for page.

Custom Post Type:

 function cptui_register_my_cpts() {

            $labels = [
                    "name" => __( "Products", "company-theme" ),
                    "singular_name" => __( "Product", "company-theme" ),
                    "menu_name" => __( "Products", "company-theme" ),
                    "all_items" => __( "All products", "company-theme" ),
                    "add_new" => __( "Add new", "company-theme" ),
                    "add_new_item" => __( "Add new product", "company-theme" ),
                    "edit_item" => __( "Edit product", "company-theme" ),
                    "new_item" => __( "New product", "company-theme" ),
                    "view_item" => __( "View product", "company-theme" ),
                    "view_items" => __( "View products", "company-theme" ),
                    "search_items" => __( "Search products", "company-theme" ),
                ];
            
                $args = [
                    "label" => __( "Produkty", "company-theme" ),
                    "labels" => $labels,
                    "description" => "",
                    "public" => true,
                    "publicly_queryable" => true,
                    "show_ui" => true,
                    "show_in_rest" => true,
                    "rest_base" => "",
                    "rest_controller_class" => "WP_REST_Posts_Controller",
                    "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" => true,
                    "rewrite" => [ "slug" => "product", "with_front" => true ],
                    "query_var" => true,
                    "menu_icon" => "dashicons-products",
                    "supports" => [ "title", "editor", "thumbnail", "excerpt", "trackbacks", "custom-fields", "comments", "revisions", "author", "page-attributes", "post-formats" ],
                    "taxonomies" => [ "product_type", "brand" ],
                    "show_in_graphql" => false,
                ];
            
                register_post_type( "product", $args );
            }
            
            add_action( 'init', 'cptui_register_my_cpts' );

Taxonomies

function cptui_register_my_taxes() {

    /**
     * Taxonomy: product type
     */

    $labels = [
        "name" => __( "Product types", "company-theme" ),
        "singular_name" => __( "Product type", "company-theme" ),
    ];

    
    $args = [
        "label" => __( "Product types", "company-theme" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => false,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => false,
        "show_admin_column" => false,
        "show_in_rest" => true,
        "show_tagcloud" => false,
        "rest_base" => "product_type",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => false,
        "show_in_graphql" => false,
    ];
    register_taxonomy( "product_type", [ "product" ], $args );

    /**
     * Taxonomy: brand
     */

    $labels = [
        "name" => __( "Brands", "company-theme" ),
        "singular_name" => __( "Brand", "company-theme" ),
    ];

    
    $args = [
        "label" => __( "Brands", "company-theme" ),
        "labels" => $labels,
        "public" => true,
        "publicly_queryable" => true,
        "hierarchical" => false,
        "show_ui" => true,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "query_var" => true,
        "rewrite" => [ 'slug' => 'brands', 'with_front' => true, ],
        "show_admin_column" => false,
        "show_in_rest" => true,
        "show_tagcloud" => false,
        "rest_base" => "brand",
        "rest_controller_class" => "WP_REST_Terms_Controller",
        "show_in_quick_edit" => false,
        "show_in_graphql" => false,
    ];
    register_taxonomy( "brand", [ "product" ], $args );
}
add_action( 'init', 'cptui_register_my_taxes' );