0

I have a custom taxonomy which has about 3 levels, parent, child, grandchild which is visible in the URL when you drill down eg:

example.com/my-cagegory/parent/child/grandchild/

And then after grandchild you get to the actual post type. But, I was hoping the url would be:

example.com/my-cagegory/parent/child/grandchild/my-product

But instead it is:

example.com/products/my-product

So, I am losing that whole taxonomy path.

function my_post_types() {

        register_post_type('product', array(
        'supports'      => array('title', 'editor', 'thumbnail', 'excerpt'),
        'rewrite'       => array('slug' => 'products'),
        'has_archive'   => true,
        'public'        => true,
        'labels'        => array(
                'name'         => 'Products',
                'add_new_item' => 'Add New Product',
                'edit_item'    => 'Edit Product', 
                'all_items'    => 'All Products',
        ),
        'menu_icon'     => 'dashicons-cart'
    ));
}


add_action('init', 'my_post_types');

function my_product_taxonomy() {

    $labels = array(
        'name' => _x( 'Product Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Product Category', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Categories' ),
        'all_items' => __( 'All Categories' ),
        'parent_item' => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item' => __( 'Edit Category' ), 
        'update_item' => __( 'Update Category' ),
        'add_new_item' => __( 'Add New Category' ),
        'new_item_name' => __( 'New Category Name' ),
        'menu_name' => __( 'Product Categories' ),
    );

    register_taxonomy('productCategory',array('product'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'show_admin_column' => true,
        'query_var' => true,
        'rewrite' => array( 'hierarchical' => true, 'slug' => 'product-category' ),
  ));   
}

 add_action('init', 'my_product_taxonomy', 0);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.