title: Wordpress Custom Type permalink with custom Taxonomy slug
body: <p>I have a custom post type on my site called Homes, with a custom taxonomy called homes-category. They are both working correctly, but I am having trouble with the permalinks. I need the permalink to be homes/homes-category/pagename. I wrote a rewrite function, so the permalink is showing up correctly whenever I go to a homes item, but I get a 404 on the page itself. I am not sure what is causing this and have no ideas on how to fix it. The homes items work fine without the custom taxonomy in the permalink, but not with it. Does anyone have any ideas on how to fix this? I've been searching for days with no luck.</p>
  
  <p>Here is the code for my custom post type:</p>
  
  <pre><code>register_post_type( 'Homes',
      array(
          'labels' =&gt; array(
              'name' =&gt; __( 'Homes' ),
              'singular_name' =&gt; __( 'Homes Item' ),
              'add_new_item' =&gt; __('Add New Homes Item'),
              'edit_item' =&gt; __('Edit Homes Item'),
              'new_item' =&gt; __('New Homes Item'),
          ),
          'supports' =&gt; array('title', 'thumbnail', 'editor'),
          'taxonomies' =&gt; array('homes-category'),
          'public' =&gt; true,
          'has_archive' =&gt; false,
          'show_in_nav_menus'   =&gt; TRUE,
          'show_in_menu'        =&gt; TRUE,
          'rewrite' =&gt; array(
              'slug' =&gt; 'homes/%homes-category%', 
              'with_front' =&gt; true,
              'hierarchical' =&gt; true,
  
             ),
      )
  );
  </code></pre>
  
  <p>Here is the code for my custom taxonomy</p>
  
  <pre><code>register_taxonomy(
      'homes-category',
      'homes',
      array(
          'hierarchical' =&gt; true,
          'label' =&gt; __( 'Availability Category' ),
          'rewrite' =&gt; array( 
              'slug' =&gt; 'homes',
              'with_front' =&gt; false,
          ),
      )
  );
  </code></pre>
  
  <p>And here is the rewrite function</p>
  
  <pre><code>function custom_post_link($post_link, $id = 0)
  {
      $post = get_post($id);
  
      if(!is_object($post) || $post-&gt;post_type != 'homes')
  {
       return $post_link;
  }
      $homes = 'misc';
  
      if($terms = wp_get_object_terms($post-&gt;ID, 'homes-category'))
  {
      $client = $terms[0]-&gt;slug;
  
  //Replace the query var surrounded by % with the slug of 
  //the first taxonomy it belongs to.
      return str_replace('%homes-category%', $homes, $post_link);
  }
  
  //If all else fails, just return the $post_link.
      return $post_link;
  }
  
  add_filter('post_type_link', 'custom_post_link', 1, 3);
  </code></pre>