First, you need to register the custom post type so that it has hierarchy, i.e. a post can have a parent post.
After that, you need to make sure your permalink structure is set to example.com/%postname%/
.
Once you have that, you only need to create a child custom post named sub-single-slug
and set single-slug
as its parent from WordPress backend Editor's Page Attribute (make sure it's checked in Screen Options
). That's all. Now your sub-single-slug
post will have the link structure as example.com/custom-post-type/single-slug/sub-single-slug/
.
For example, I register the custom post type as follows:
function wpse_register_custom_post_type() {
$labels = array(
"name" => __( 'custom post type', 'text-domain' ),
"singular_name" => __( 'custom post types', 'text-domain' ),
);
$args = array(
"label" => __( 'custom post type', 'text-domain' ),
"labels" => $labels,
"description" => "",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_menu" => true,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => true,
"rewrite" => array( "slug" => "custom_post_type", "with_front" => true ),
"query_var" => true,
"supports" => array( "title", "editor", "thumbnail", "custom-fields", "page-attributes" ),
"taxonomies" => array( "category", "post_tag" ),
);
register_post_type( "custom_post_type", $args );
}
add_action( 'init', 'wpse_register_custom_post_type' );