Same Custom Post Type Slug and Custom Taxonomy Slug, with hierarchial unique permalink structure

I am new to wordpress custom post type and re-writing urls’.

I have created a Custom Post Type with slug ‘industries‘ and Custom Taxonomy associated to it with same slug ‘industries‘. The taxonomy archive pages will have nested (hierarchial) pages.

I want following urls’ to work:

  1. https://example.com/industries
  • Lists parent taxonomies, for which created custom page template, works fine.
  1. https://example.com/industries/parent-taxonomy
  • Lists child taxonomies, taxonomy-industries.php, works fine.
  1. https://example.com/industries/parent-taxonomy/child-taxonomy
  • Lists posts, same template taxonomy-industries.php, works fine.
  1. https://example.com/industries/parent-taxonomy/post-slug
  • Should display post content, instead shows 404 page not found error.

However if I manually try to access single page with taxonomies hierarchy in url, it displays content as it should.

  • https://example.com/industries/automotive-transportation/auto-manufacturing/manufacturing-digital-marketing/

I want to make this url working for post detail page:

  • https://example.com/industries/automotive-transportation/manufacturing-digital-marketing/

Here ‘automotive-transportation’ is parent taxonomy and ‘manufacturing-digital-marketing’ is post slug.

Here is the code I wrote so far.

//Custom Post Type
function cpt_industry() {
    $args = array(
        'label'             => __( 'Industry', 'sevenc' ),
        'labels'            => array( 'name' => 'Industries', 'singular_name' => 'Industry', ),
        'public'            => true,
        'hierarchical'      => true,
        'has_archive'       => false,
        'show_in_menu'      => true,
        'show_in_admin_bar' => true,
        'menu_position'     => 5,
        'supports'          => array( 'title', 'custom-fields', 'thumbnail', 'editor', 'excerpt'),
        'rewrite'           => array('slug' => 'industries/%industries%/%industries%', 'with_front' => true),
    );
    register_post_type( 'industry', $args );
}
add_action( 'init', 'cpt_industry', 0 );

//Custom Taxonomy - Industries
function ctax_industries() {
    $args = array(
        'labels'            => array( 'name' => 'Industries Categories', 'singular_name' => 'Industry Category', ),
        'show_ui'           => true,
        'show_admin_column' => true,
        'hierarchical'      => true,
        'public'            => true,
        'query_var'         => true,
        'rewrite'           => array('slug' => 'industries', 'with_front' => true, 'hierarchical' => true ),
    );

    register_taxonomy( 'industries', array( 'industry' ), $args );
}
add_action( 'init', 'ctax_industries', 0 );

//post_type_link() Hook
function custom_post_type_link($post_link, $post) {
    if ($post->post_type == 'industry') {
        $terms = wp_get_object_terms($post->ID, 'industries');
        if ($terms && !is_wp_error($terms)) {
            // Get the parent term
            $parent_term = $terms[0];
            while ($parent_term->parent != 0) {
                $parent_term = get_term($parent_term->parent, 'industries');
            }
            $post_link = str_replace('%industries%/%industries%', $parent_term->slug, $post_link);
        } else {
            $post_link = str_replace('%industries%/%industries%', 'uncategorized', $post_link);
        }
    }
    return $post_link;
}
add_filter('post_type_link', 'custom_post_type_link', 1, 2);

I am trying this since past 2 days, and I am so stuck, any help would be highly appreciated.

Thank you!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật