title: Wordpress conditional URL rewrite with multiple custom taxonomy terms
body: <p>I'm hoping someone will be able to help me with a Wordpress URL rewrite...i've attempted a couple but have got nowhere near so far. To give you an overview of where I am at...</p>
  
  <p><strong>I first register my taxonomy</strong></p>
  
  <pre><code>function curriculum_taxonomy() {
    register_taxonomy(
      'taxonomy_type',  
      'taxonomy',        
      array(
          'hierarchical' =&gt; true,
          'show_admin_column' =&gt; true,
          'label' =&gt; 'taxonomy type', 
          'query_var' =&gt; true,
          'rewrite' =&gt; array(
              'slug' =&gt; 'taxonomy', 
              'with_front' =&gt; true,
              'hierarchical' =&gt; true
          )
      )
    );
  }
  add_action( 'init', 'curriculum_taxonomy');
  </code></pre>
  
  <p>registered taxonomy_type with a rewritten slug of taxonomy</p>
  
  <p><strong>so currently the URL is www.baseurl/taxonomy</strong></p>
  
  <p>then I register the post_type whose relevant args are</p>
  
  <pre><code>    $args = array(
      'capability_type' =&gt; 'post',
      'rewrite'         =&gt; array('slug' =&gt; 'taxonomy/%parent_term%','with_front' =&gt; false),
      'taxonomies'      =&gt; 'taxonomy_type',
      'query_var' =&gt; true,
      'can_export' =&gt; true,
      'publicly_queryable' =&gt; true,
  
    );
  </code></pre>
  
  <p>I then programatically swap out the %parent_term% with the term slug</p>
  
  <pre><code>function filter_taxonomy_link($link, $post) {
      if ($post-&gt;post_type != 'taxonomy') {
          return $link;
      }
      if ($cats = get_the_terms($post-&gt;ID, 'taxonomy_type')) {
        $linkSlug = array_pop($cats)-&gt;slug;
        $link = str_replace('%parent_term%', $linkSlug, $link);
        return $link;
      }
  }
  add_filter('post_type_link', 'filter_curriculum_link', 10, 2);
  </code></pre>
  
  <p><strong>so my URL is currently www.baseurl/taxonomy/[parent-term]/</strong> with taxonomy being static</p>
  
  <p>This gives me 90% correct URL's</p>
  
  <p>now here's where i'm running into problems...</p>
  
  <p>this structure exists <strong>www.baseurl/taxonomy/[parent-term]/[post_name]</strong> (for example post_name might be an about page or some page relating to that parent term.</p>
  
  <p>This structure also exists <strong>www.baseurl/taxonomy/[parent-term]/content</strong> which is a custom archive of all child-terms. One of these will exist per parent-term. content is a static slug.</p>
  
  <p>What i'm needing is a rewrite of <strong>www.baseurl/taxonomy/[parent-term]/content/[child_post_name]</strong> only when [child_post_name] has a [child-term]. And also  a rewrite of <strong>www.baseurl/taxonomy/[parent-term]/content/[child_post_name]/[grandchild_post_name]</strong> only when [grandchild_post_name] has a [grandchild-term]. </p>
  
  <p>So to rephrase that...</p>
  
  <p>if a post has only one parent term, the url should be <strong>www.baseurl/taxonomy/[parent-term]/[post_name]</strong> which I already have working.</p>
  
  <p>but if a post has a child term then it should be <strong>www.baseurl/taxonomy/[parent-term]/content/[child_post_name]</strong></p>
  
  <p>and lastly if a post has a grandchild term then it should be <strong>www.baseurl/taxonomy/[parent-term]/content/[child_post_name]/[grandchild_post_name]</strong></p>
  
  <p>i'm really not sure how to go about making that relationship between child_post_name and grandchild_post_name. One idea i've had was to make the child_post_name another custom post type and prepend a rewrite to it so it fits in that structure...but thats a LOT of work and even at least some kind of confirmation on that would make me feel better about it.</p>
  
  <p>even a point in the right direction would be greatly appreciated as i'm pretty stumped by this.</p>
  
  <p>thanks.</p>