title: Wordpress Add Taxonomy tag to permalink custom post type
body: <p>I am searching days now for the answer how to add taxonomy to my custom post type permalink. I've found this article which almost exactly gives the answer but it doesn't work for my custom post type.
  <a href="http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks" rel="nofollow">http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks</a></p>
  
  <p>The article describes that you first make a simple Taxonomy:</p>
  
  <pre><code>add_action('init', 'my_rating_init');
  
  
      function my_rating_init() {
          if (!is_taxonomy('rating')) {
              register_taxonomy( 'rating', 'post', 
                         array(   'hierarchical' =&gt; FALSE, 'label' =&gt; __('Rating'),  
                              'public' =&gt; TRUE, 'show_ui' =&gt; TRUE,
                              'query_var' =&gt; 'rating',
                              'rewrite' =&gt; true ) );
          }
      }
  </code></pre>
  
  <p>And then you can rewrite the url in your Wordpress system like: /%rating%/%postname%</p>
  
  <p>And then you need to translate %rating% to the taxonomy tags by doing:</p>
  
  <pre><code>add_filter('post_link', 'rating_permalink', 10, 3);
  add_filter('post_type_link', 'rating_permalink', 10, 3);
  
  function rating_permalink($permalink, $post_id, $leavename) {
      if (strpos($permalink, '%rating%') === FALSE) return $permalink;
  
          // Get post
          $post = get_post($post_id);
          if (!$post) return $permalink;
  
          // Get taxonomy terms
          $terms = wp_get_object_terms($post-&gt;ID, 'rating');   
          if (!is_wp_error($terms) &amp;&amp; !empty($terms) &amp;&amp; is_object($terms[0])) $taxonomy_slug = $terms[0]-&gt;slug;
          else $taxonomy_slug = 'not-rated';
  
      return str_replace('%rating%', $taxonomy_slug, $permalink);
  }   
  </code></pre>
  
  <p>This works fine for "post" but when I change: </p>
  
  <pre><code>register_taxonomy( 'rating', 'post',
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>register_taxonomy( 'rating', 'mycustomposttype', 
  </code></pre>
  
  <p>The URL rewrite doesn't work anymore. And only gives the following url:</p>
  
  <p><a href="http://www.website.com/custom-post-type/post" rel="nofollow">http://www.website.com/custom-post-type/post</a></p>
  
  <p>Where I want this:</p>
  
  <p><a href="http://www.website.com/custom-post-type/taxonomy-tag/post" rel="nofollow">http://www.website.com/custom-post-type/taxonomy-tag/post</a></p>
  
  <p>So my 2 questions are:</p>
  
  <ol>
  <li>How can I make this work for my custom post type?</li>
  <li>How can I make this work only for my custom post type? Because I need to add %rating% to my wordpress system (settings -> permalinks) so it changes all my URLS.</li>
  </ol>