• After many countless hours of scouring this forum and the web I still haven’t found a solution to my problem. I set up a custom post type called ‘product’ and a taxonomy called ‘product-category’. I am trying to achieve a parent/child url structure like the following:
    /term/subterm/post-name. A real world example is: /vectors/design-elements/engraved. The following is the code I have in functions.php.

    add_action('init', 'post_type_product');
    function post_type_product() {
    	register_post_type('product', array(
    		'label' => __('Products'),
    		'singular_label' => __('Product'),
    		'public' => true,<br />
    		'show_ui' => true, // UI in admin panel
    		'_edit_link' => 'post.php?post=%d',
    		'capability_type' => 'post',
    		'hierarchical' => false,
    		'rewrite' => array("slug" => ""), // Permalinks format
    		'supports' => array('title','editor','custom-fields','page-attributes')
    	));
    }
    add_action( 'init', 'create_productcategory_taxonomy');
    function create_productcategory_taxonomy() {
        $labels = array(
            'name' => _x( 'Categories', 'taxonomy general name' ),
            'singular_name' =>_x( 'Category', 'taxonomy singular name' ),
            'search_items' =>  __( 'Search Categories' ),
            'popular_items' => __( 'Popular Categories' ),
            'all_items' => __( 'All Categories' ),
            'parent_item' => null,
            'parent_item_colon' => null,
            'edit_item' => __( 'Edit Product Category' ),
            'update_item' => __( 'Update Product Category' ),
            'add_new_item' => __( 'Add New Product Category' ),
            'new_item_name' => __( 'New Product Category' ),
            'separate_items_with_commas' => __( 'Separate categories with commas' ),
            'add_or_remove_items' => __( 'Add or remove product categories' ),
            'choose_from_most_used' => __( 'Choose from the most used categories' )
            );
        register_taxonomy('product-category', array('product'), array (
            'hierarchical' => true,
            'labels' => $labels,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => array('hierarchical' => true, 'with_front' => false, 'slug' => 'categories'),
           ));
    }

    Apparently having ‘hierarchical’ => true, and ‘rewrite’ => array(‘hierarchical’ => true) is supposed to allow for hierarchical urls but its not working for me. I would be extremely grateful if someone could help me out.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom post type, taxonomies and url rewriting’ is closed to new replies.