custom post type and custom taxonomy permalink

I have 2 pages.

/client-a/
/client-b/

I have a custom post type, called “case”:

Read More
$case_type = array(
    'labels' => $case_labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => 'case',
    'rewrite' => array( 'slug' => 'cases', 'with_front' => false ),
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => 46,
    'has_archive' => true,
    'supports' => array('title','editor'),
); 
register_post_type( 'case' , $case_type );

And finally I have a custom taxonomy, called “type”:

register_taxonomy('type',array('case'),array(
    'public' => TRUE,
    'show_tagcloud' => FALSE,
    'hierarchical' => TRUE,
    'labels' => $categoria_labels,
    'show_ui' => TRUE,
    'query_var' => TRUE,
    'rewrite' => array( 'slug' => 'genre', 'with_front' => false )
))

All my types has the same name of my pages: client-a, client-b.

How can I rewrite the permalink rules to accept this structure:

client-a/ --> page, lists all 'cases', uses a template
client-a/subpage --> this is a subpage

client-a/cases/case-a.html --> this is a custom post type WITH the genre "client-a"
client-b/cases/case-b.html --> this is a custom post type WITH the genre "client-b"

What is the best approach for this structure?

Whem I’m using this solution:
http://xplus3.net/2010/05/20/wp3-custom-post-type-permalinks/comment-page-1/#comment-1005

I get my permalinks working for custom post types and custom taxonomy, but breaks all my pages permalinks.

Thanks!

Related posts

Leave a Reply

1 comment

  1. Something similar to this in your functions.php or a plugin will do the trick:

    function custom_rewrite( $wp_rewrite ) {
        $feed_rules = array(
            '([^/]+)/cases/([^/]+).html'    =>  'index.php?genre='. $wp_rewrite->preg_index(1) .'&case='. $wp_rewrite->preg_index(2)
        );
        $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
    }
    // refresh/flush permalinks in the dashboard if this is changed in any way
    add_filter( 'generate_rewrite_rules', 'custom_rewrite' );
    

    You will need to refresh/flush your permalinks (WP Dashboard > Settings > Permalinks > Save Changes) when you add/edit/remove that code. You may need to adjust it slightly if it doesn’t work as is, but it demonstrates the basic principle of how to do it.