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.

Is there any way to add %post_type% and %taxonomy% to permalinks? I want to have links from one custom post type have one taxonomy's terms in its permalink, and another post type to use another taxonomy's terms.

share|improve this question
    
Can you please be more specific? Update your question with the names of your current custom post types and custom taxonomies. And then tell us what type of Custom Permalink you are trying to set for them. –  Hameedullah Khan Jun 20 '11 at 4:48
add comment

2 Answers

up vote 2 down vote accepted

I will try to answer the question in detailed but keeping it as short as possible considering you have achieved the basics. Suppose our custom post type one is to be connected to taxonomy one. Let's call them 'console'(custom post type) and 'brands'(taxonomy). You want to achieve: http://example.com/console/brands/sony/ Steps: Register the taxonomy first and attach it to custom post type console.

$labels = array(
    'name'                          => 'Brands',
    'singular_name'                 => 'Brand',
    'search_items'                  => 'Search Brands',
    'popular_items'                 => 'Popular Brands',
    'all_items'                     => 'All Brands',
    'parent_item'                   => 'Parent Brand',
    'edit_item'                     => 'Edit Brand',
    'update_item'                   => 'Update Brand',
    'add_new_item'                  => 'Add New Brand',
    'new_item_name'                 => 'New Brand',
    'separate_items_with_commas'    => 'Separate Brands with commas',
    'add_or_remove_items'           => 'Add or remove Brands',
    'choose_from_most_used'         => 'Choose from most used Brands'
    );

$args = array(
    'label'                         => 'Brands',
    'labels'                        => $labels,
    'public'                        => true,
    'hierarchical'                  => true,
    'show_ui'                       => true,
    'show_in_nav_menus'             => true,
    'args'                          => array( 'orderby' => 'term_order' ),
    'rewrite'                       => array( 'slug' => 'consoles/brands', 'with_front' => false ),
    'query_var'                     => true
);

register_taxonomy( 'brands', 'consoles', $args );

Note here that the rewrite key in our $args array. That value is telling WordPress the slug to use in our Custom Taxonomy. We don’t want it prepended with the WordPress permalink front base, which defaults to true, and we want the slug to include our Custom Post Type rewrite slug.

Step Two: Now create the custom post type.I'm not writing the whole code but remember the important parameter here is the 'rewrite'

'rewrite'               => array( 'slug' => 'consoles', 'with_front' => false ),

visit your Settings > Permalinks options screen in the WordPress admin to ensure your new permalinks are picked up

Repeat the steps for second custom post type and taxonomy 2.:)cheers.. PS:You need to define has_archive key to have archive page.

share|improve this answer
    
Yes, I had made this more complicated than it was. An alternative way to frame my question would have been, "How do I insert the post_type (e.g., consoles) at the beginning of the permalink, before a custom taxonomy's terms. You answer solves that; the only thing this wouldn't work for is if you wanted to use the same taxonomy in more than one post type's permalinks. Like—in addition to /consoles/brands/sony (using CPT consoles), having /reviews/brands/sony (using CPT reviews). –  supertrue Aug 23 '11 at 20:06
add comment

@supertrue I can't comment so i post it as answer. Have you find a solution for the second situation to use the same taxonomy for a second custom post type (in your example CPT reviews)?

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.