Custom Postype Slug Issue
-
Heh guys,
I’m trying to do something that should be relatively simple but struggling to get the urls I want to work.
Bascially I want to have the ability to create new products and have the relevant product pages within them. This I have done using custom post types, defining a new custom post type and new custom taxonomy.
The problem I’m having is with the rewrite rule. When I use the one defined in the code below, it works for that particular custom post when I flush the permalinks, however the other pages on the site do not (It throws a 404)! When I replace it with “products/product-name/subpage” it seems to work fine. Seems a bit odd.
I want to have the following permalink (commented out in code below)
product-name/subpageCurrently I can only get this to work
products/product-name/subpageSee code below. I also have a function to replace the Taxonomy slug with Post Type slug in url in my functions.php file.
Would be great if anyone could give me a hand with this.
function my_custom_post_work() { $labels = array( 'name' => _x( 'Product Feature', 'post type general name' ), 'singular_name' => _x( 'Product Feature', 'post type singular name' ), 'add_new' => _x( 'Add New Product Feature', 'book' ), 'add_new_item' => __( 'Add New Product Feature' ), 'edit_item' => __( 'Edit Product Feature' ), 'new_item' => __( 'New Product Feature' ), 'all_items' => __( 'All Product Features' ), 'view_item' => __( 'View Product Feature' ), 'search_items' => __( 'Search Product Feature' ), 'not_found' => __( 'No Product Feature found' ), 'not_found_in_trash' => __( 'No Product Feature found in the Trash' ), 'parent_item_colon' => '', 'menu_name' => 'Products' ); $args = array( 'labels' => $labels, 'description' => 'Contains all Product Features', 'public' => true, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields' ), 'has_archive' => false, // 'rewrite' => array( 'slug' => '%product_category%') 'rewrite' => array( 'slug' => 'products/%product_category%') ); register_post_type( 'work', $args ); } add_action( 'init', 'my_custom_post_work' ); function mav_taxonomies_work() { $labels = array( 'name' => _x( 'Product Categories', 'taxonomy general name' ), 'singular_name' => _x( 'Product Category', 'taxonomy singular name' ), 'search_items' => __( 'Search Product Categories' ), 'all_items' => __( 'All Product Categories' ), 'parent_item' => __( 'Parent Product Category' ), 'parent_item_colon' => __( 'Parent Product Category:' ), 'edit_item' => __( 'Edit Product Category' ), 'update_item' => __( 'Update Product Category' ), 'add_new_item' => __( 'Add New Product Category' ), 'new_item_name' => __( 'New Product Category' ), 'menu_name' => __( 'Product Categories' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'has_archive' => false, ); register_taxonomy( 'product_category', 'work', $args ); } add_action( 'init', 'mav_taxonomies_work', 0 );
The topic ‘Custom Postype Slug Issue’ is closed to new replies.