We are currently developing a new wp theme and all the current posts are moved to a new CPT called products. For SEO the links to the products need to be remained.
The current structure of the post type is:
www.url.com/category-a/category-b/productname
After moving the items from the default post type to the new CPT the URL looks like:
www.url.com/products/productname
But we want to remain the default post structure for these posts. The archive pages show the products, so that’s working fine.
My permalink setting is:
/%category%/%pagename%
So basicly we want to change: www.url.com/products/productname
To: www.url.com/category-a/subcategory-a/productname
This is our CPT we created:
function cptui_register_my_cpts_producten() {
/**
* Post Type: Producten.
*/
$labels = array(
"name" => __( "Producten", "sage" ),
"singular_name" => __( "Product", "sage" ),
"archives" => __( "Producten Archief", "sage" ),
);
$args = array(
"label" => __( "Producten", "sage" ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => false,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => true,
"rewrite" => array( "slug" => "producten", "with_front" => false ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail" ),
"taxonomies" => array( "category" ),
);
register_post_type( "producten", $args );
}
add_action( 'init', 'cptui_register_my_cpts_producten' );