title: Custom Post Type Slug clash
body: <p>I have multiple custom post types with custom taxonomies. I'm having a slug clash despite of having different parents.</p>
  
  <p>Here is my URL structure:
  /work/%client_name%/%project_name%</p>
  
  <p>I have a client (client1) and project (some-cool-project-name) that generates this slug: "/work/client1/some-cool-project-name".</p>
  
  <p>When I create a new post under a different parent (client) and give the same name (and slug) to the post, wordpress appends -2 to the slug: "/work/client2/some-cool-project-name-2"</p>
  
  <p>Custom post type as:</p>
  
  <pre><code>// Custom taxonomies.
  function custom_taxonomies() {
      $args = array(
          'label' =&gt; __( 'Work', '' ),
          'labels' =&gt; array(
              'name' =&gt; __( 'Work', '' ),
              'singular_name' =&gt; __( 'Work', '' ),
          ),
          'description' =&gt; '',
          'public' =&gt; true,
          'publicly_queryable' =&gt; true,
          'show_ui' =&gt; true,
          'show_in_rest' =&gt; false,
          'rest_base' =&gt; '',
          'has_archive' =&gt; true,
          'show_in_menu' =&gt; true,
          'exclude_from_search' =&gt; false,
          'capability_type' =&gt; 'post',
          'map_meta_cap' =&gt; true,
          'hierarchical' =&gt; true,
          'rewrite' =&gt; array( 'slug' =&gt; 'work/%client_name%', 'with_front' =&gt; true ),
          'query_var' =&gt; true,
          'menu_icon' =&gt; 'dashicons-hammer',
          'supports' =&gt; array( 'title', 'editor', 'thumbnail', 'excerpt', 'page-attributes' ),
          'taxonomies' =&gt; array( 'client_name' ),
      );
      register_post_type( 'work', $args );
  
      $args = array(
          'label' =&gt; __( 'Clients', '' ),
          'labels' =&gt; array(
              'name' =&gt; __( 'Clients', '' ),
              'singular_name' =&gt; __( 'Client', '' ),
          ),
          'public' =&gt; true,
          'hierarchical' =&gt; false,
          'label' =&gt; 'Clients',
          'show_ui' =&gt; true,
          'show_in_menu' =&gt; true,
          'show_in_nav_menus' =&gt; true,
          'query_var' =&gt; true,
          'rewrite' =&gt; array( 'slug' =&gt; 'work/client_name', 'with_front' =&gt; false, ),
          'show_admin_column' =&gt; false,
          'show_in_rest' =&gt; false,
          'rest_base' =&gt; '',
          'show_in_quick_edit' =&gt; false,
      );
      register_taxonomy( 'client_name', array( 'work' ), $args );
  }
  add_action( 'init', 'custom_taxonomies' );
  </code></pre>
  
  <p>And my permalink rewrite:</p>
  
  <pre><code>// Replace URL with proper taxonomy structure.
  function permalink_rewrites( $link, $post ) {
      if ( $post-&gt;post_status !== 'publish' || $post-&gt;post_type != 'work' ) {
          return $link;
      }
  
      if ( $post-&gt;post_type == 'work' ) {
          $type = '%client_name%/';
          $filters = get_the_terms( $post-&gt;ID, 'client_name' );
          $slug = $filters[0]-&gt;slug . '/';
      }
  
      if ( isset( $slug ) ) {
          $link = str_replace( $type, $slug, $link );
      }
  
      return $link;
  }
  add_filter( 'post_type_link', 'permalink_rewrites', 10, 2 );
  </code></pre>
  
  <p>Any suggestions on what I can do this fix this?</p>
  
  <p>Thanks.</p>