Custom Permalinks For CPT and pages with parent. Advanced WordPress

Did a quick test on my local dev – https://pastebin.com/bP8byGHR – look for the comments // here.

On your taxonomies I had to remove capabilities because it wasn’t showing on my menu, ignore if it works for you but I don’t see any use case for it.

Your rewrites were the issue, you can fix the permalinks structure with post_type_link:

add_filter('post_type_link', 'so_update_permalink_structure', 10, 2);

function so_update_permalink_structure( $post_link, $post )
{
    if ( false !== strpos( $post_link, '%community_post_domain%' ) ) {
        $taxonomy_terms = get_the_terms( $post->ID, 'community_post_domain' );
        foreach ( $taxonomy_terms as $term ) {
            if ( ! $term->parent ) {
                $post_link = str_replace( '%community_post_domain%', $term->slug, $post_link );
            }
        }
    }
    return $post_link;
}

Don’t forget to flush permalinks and test.

With a quick search I’ve found a blog post that explains much better than me and it can be useful for your case: https://react2wp.com/using-same-slug-for-custom-post-type-and-custom-taxonomy/

edit: My permalinks tests:


// Created a page with the same slug
// Test url: ok
url.test/community/

// Created the taxonomy 'kubernetes'
// Test url: ok
url.test/community/kubernetes/

// Created a new cpt post
// Post with a taxonomy: ok
url.test/community/kubernetes/go-micro-services/

// Post without a taxonomy: error 400
// For this case you should set a default taxonomy to prevent an error
url.test/community/%community_post_domain%/go-micro-services/