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.

Recently I have been working on an advanced WordPress project, and I'm stuck with changing permalink structure for custom post types.

I have created 3 post types lets say: type1, type2, type3 and a taxonomy test registered for all of them. I have 3 terms in the custom taxonomy cat1, cat2 ,cat3

Here's what I want to achieve:

instead of accessing all posts from cat by

siteurl/test/cat1

I want to access each post-type archives by taxonomy cat like:

siteurl/type1/cat1

share|improve this question
    
what is url structure ? –  amit Aug 2 '12 at 17:19
1  
I think you are confuse with custom post type and taxonomies... but if you provide the real names you are using will help me to understand it better. For example is type1 = vehicle , cat1 = type and term1 = car . –  chifliiiii Aug 9 '12 at 18:13
1  
I agree with @chifliiiii that it may help us if you clarify exactly how/what you're attempting to organise. Also categories can have sub-categories which may be easier for forming a structured hierarchy. –  Chris Aug 21 '12 at 9:55
    
This post might have some more detail and direction for you: wordpress.stackexchange.com/questions/49141/… –  Alex V. Sep 28 '12 at 4:55
add comment

2 Answers

Without having more specific terms to help me understand what you're actually trying to organize, I'm not sure I'm on the right track, but does this plugin help you accomplish what you're trying to do? http://wordpress.org/extend/plugins/cpt-onomies/

It kind of conflates custom-type post titles and taxonomies in an odd (and possibly useful?) way...

share|improve this answer
add comment

Here is part of the code from one of my projects to setup a similar structure for permalinks (same base slug for both the post type and the taxonomy archives), please note the values of 'has_archive' and 'rewrite' parameters of both the post type and the taxonomy:

add_action( 'init', 'register_my_post_types' );
function register_my_post_types() {

  register_post_type( 'movie',
    array(
        ....

        'has_archive' => 'movies',
        'rewrite' => array(
            'slug' => 'movies/%mv_category%',
            'with_front' => false
        ),
        'taxonomies' => array(
            'mv_category',
        ),
    )
  );

  register_taxonomy(
    'mv_category',
    array(
        'movie'
    ),
    array(
        ...
        'hierarchical' => true,
        'rewrite' => array(
            'slug' => 'movies',
            'with_front' => false,
            'hierarchical' => false
        )
    )
  );
) // end of create_my_post_types function


add_filter('post_type_link', 'filter_post_type_link', 10, 2);
function filter_post_type_link($link, $post)
{
    if ($post->post_type != 'movie')
        return $link;

    if ($cats = get_the_terms($post->ID, 'mv_category'))
        $link = str_replace('%mv_category%', array_pop($cats)->slug, $link);

    return $link;
}

Then you can access 'Documentary' category of Movie post type with this url:

site.com/movies/documentary/

and 'Movie A' of 'Documentary' category will be:

site.com/movies/documentary/movie-a/

NOTE: It's important to register the taxonomy after the post type, because of the order permalink rewrite rules are generated in WordPress.

share|improve this answer
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.