Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have set up a custom taxonomy on a custom post type using the following: (For the sake of example, the custom post type is called newtype and the new taxonomy is just called newtax.

// Create Custom Post Type for newpost
add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'x_newtype',
        array(
            'labels' => array(
                'name' => __( 'New Type' ),
                'singular_name' => __( 'New Type' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'newtype'),
            'taxonomies' => array('category', 'post_tag'),
            'supports' => array('title','editor','excerpt','thumbnail')
        )
    );
}


// Add custom field for custom post type
function new_taxonomy() {
   register_taxonomy(
    'newtax',
    'x_newtype',
    array(
        'hierarchical' => true,
        'label' => 'New Tax',
        'query_var' => true,
        'rewrite' => array('slug' => 'newtax')
    )
);
}
add_action( 'init', 'new_taxonomy' );

This works fine, but I had a question in regards to the URL redirecting.

Currently, if you go to http://www.domain.com/newtype/newtax-term/post-name/ it will redirect to http://www.domain.com/newtype/post-name/ . What is the best way to allow http://www.domain.com/newtype/newtax-term/post-name/ to load, without redirecting?

Thanks for reading.

share|improve this question
    
have you flushed your permalinks after setting: 'rewrite' => array('slug' => 'newtax') ? –  moraleida Jun 4 '12 at 19:39
    
The permalink cache has been flushed by visiting Settings --> Permalinks --> Save. –  Ryan Jun 4 '12 at 20:37
add comment

1 Answer

up vote 2 down vote accepted

What is the best way to allow http://www.domain.com/newtype/newtax-term/post-name/ to load, without redirecting?

You have to add a custom rewrite rule to make this work. Otherwise WordPress doesn't understand the newtax-term part of your permalink structure and redirects you to the URL which it does understand, which is %post_type%/%post_slug%.

If you want to understand how WordPress Rewrite API works, I would recommend you to read The Rewrite API: The Basics article. Spare no effort to learn it and you won't have issues with it.

share|improve this answer
    
Thanks for the reply! And I'm going to assume you mean /%post-slug%/ ;) Either way, the Rewrite API link looks like it will be very useful. –  Ryan Jun 15 '12 at 16:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.