Use different taxonomies in different custom post types’ permalinks?

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.

Related posts

Leave a Reply

1 comment

  1. 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.