title: WordPress custom post type link are changed but returns 404
body: <p>WordPress custom post type link are changed but returns 404.</p>
  <p>I have created a custom post type like this,</p>
  <pre><code>function create_notes_custom() {
  
      register_post_type( 'coaches_resources',
          array(
              'labels' =&gt; array(
                  'name' =&gt; __( 'Coaches Resources' ),
                  'singular_name' =&gt; __( 'Coaches Resource' ),
                  'add_new' =&gt; __( 'Add New' ),
                  'add_new_item' =&gt; __( 'Add New Resource' ),
                  'edit' =&gt; __( 'Edit' ),
                  'edit_item' =&gt; __( 'Edit Resource' ),
                  'new_item' =&gt; __( 'New Resource' ),
                  'view' =&gt; __( 'View' ),
                  'view_item' =&gt; __( 'View Resource' ),
                  'search_items' =&gt; __( 'Search Resources' ),
                  'not_found' =&gt; __( 'No resources found' ),
                  'not_found_in_trash' =&gt; __( 'No resource found in Trash' ),
                  'parent' =&gt; __( 'Parent Resource' )
              ),
              'public' =&gt; true,
              'menu_position' =&gt; 5,
              'supports' =&gt; array( 'title' ),
              'taxonomies' =&gt; array( 'resource_chapter' ),
              'rewrite' =&gt; array( 'slug' =&gt; 'resource', 'with_front' =&gt; true ),
              'has_archive' =&gt; false,
              'hierarchical' =&gt; false
          )
      );
  }
  add_action('init', 'create_notes_custom');
  </code></pre>
  <p>URL is changed by,</p>
  <pre><code>function change_link( $permalink, $post ) {
      
      if( $post-&gt;post_type == 'coaches_resources' ) {
          $resource_terms = get_the_terms( $post, 'resource_chapter' );
          $term_slug = '';
          if( ! empty( $resource_terms ) ) {
              foreach ( $resource_terms as $term ) {
              
              
                  if (! empty($term-&gt;slug))  {
                      
                      // The featured resource will have another category which is the main one
                      if( $term-&gt;slug == 'featured' ) {
                          continue;
                      }
      
                      $term_slug = $term-&gt;slug;
                      break;
                  }
              }
          }
          $permalink = get_home_url() .&quot;/notebook/&quot; . $term_slug . '/' . $post-&gt;post_name;
      }
      return $permalink;
  
  }
  add_filter('post_type_link', &quot;change_link&quot;, 10, 2);
  </code></pre>
  <p>URL is changed from
  <a href="http://example.com/resource/my-first-note/" rel="nofollow noreferrer">http://example.com/resource/my-first-note/</a>
  to
  <a href="http://example.com/notebook/note-category/my-first-note" rel="nofollow noreferrer">http://example.com/notebook/note-category/my-first-note</a></p>
  <p>But it returns <code>404</code>.</p>