Custom permalink structure

I’ll look into the last two soon but for the top 3 you could do the following:

mysite.com/post-type-slug/post1:

This defaults to the post type name you specify when registering it but can be altered by changing the rewrite argument in the register_post_type() call.

register_post_type( 'posttype', array(
    // ... all the other args...
    'rewrite' => array( 'slug' => 'post-type-slug' ),
    // if you want to list a post type with no taxonomy involvement
    'has_archive' => 'post-type-slug'
) );

mysite.com/post-type-slug/taxonomy1-term:

I don’t think you can easily get the hyphen between the taxonomy name and the term name if that’s what you mean but you can do the following:

register_taxonomy( 'taxonomy1', 'posttype', array(
    // ... all the other args...
    'rewrite' => array( 'slug' => 'post-type-slug/taxonomy-slug' )
) );

Which will give you a URL like this:

mysite.com/post-type-slug/taxonomy-slug/term

I wasn’t too sure from your question but if you don’t want the taxonomy-slug to be there then you’re out of luck, you can’t have the same slug as your post type or another taxonomy as it won’t know what term is from which taxonomy and what’s a post.

To get the heirarchical terms URL do this:

register_taxonomy( 'taxonomy1', 'posttype', array(
    // ... all the other args...
    'rewrite' => array( 'slug' => 'post-type-slug/taxonomy-slug', 'heirarchical' => true )
) );

Which gives you

mysite.com/post-type-slug/taxonomy-slug/term/sub-term

Note:

If it helps setting slug to false gets rid of it altogether so you’d get:

mysite.com/term/sub-term

Leave a Comment