Using CPT slug within taxonomy rewrite causes 404

Question

I have set up a CPT called ‘recipes’ and have added a custom taxonomy under this called ‘categories’.
(The main purpose of this is to separate the recipe categories from the blog categories)

I am having trouble getting the rewrites to work, everything I try fails unless I use a different slug to ‘recipes’. Is there a workaround?

My desired url is:

www.websiteaddress/recipes/

www.websiteaddress/recipes/post-name

www.websiteaddress/recipes/category/category-name

My functions look like this:


*** CUSTOM POST TYPE ***

register_taxonomy_for_object_type('category', 'recipes'); // Register Taxonomies for Category
    register_taxonomy_for_object_type('post_tag', 'recipes');
    register_post_type('recipes', // Register Custom Post Type
        array(
        'labels' => array(
            'name' => __('Recipes', 'recipes'), // Rename these to suit
            'singular_name' => __('Recipes', 'recipes'),
            'add_new' => __('Add New', 'recipes'),
            'add_new_item' => __('Add New', 'recipes'),
            'edit' => __('Edit', 'recipes'),
            'edit_item' => __('Edit', 'recipes'),
            'new_item' => __('New', 'recipes'),
            'view' => __('View', 'recipes'),
            'view_item' => __('View', 'recipes'),
            'search_items' => __('Search', 'recipes'),
            'not_found' => __('No recipes found', 'recipes'),
            'not_found_in_trash' => __('No recipes found in Trash', 'recipes')
        ),
        'public' => true,
        'hierarchical' => false, // Allows your posts to behave like Hierarchy Pages
        'has_archive' => true,
        'menu_icon' => 'dashicons-groups',
        'supports' => array(
            'title',
        ), // Go to Dashboard Custom theme_ Blank post for supports
        'can_export' => true, // Allows export in Tools > Export
        'taxonomies' => array(
            //'post_tag',
            //'category'
        ), // Add Category and Post Tags support
    ));

*** Taxonomy ***

function themes_taxonomy() {
    register_taxonomy(  
        'categories',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
        'recipes',  //post type name
        array(  
            'hierarchical' => true,  
            'label' => 'Recipe Category',  //Display name
            'query_var' => true,
            'show_admin_column' => true,
            'rewrite' => array(
                'slug' => 'recipes/category', // This controls the base slug that will display before each term
                'with_front' => false // Don't display the category base before 
            )
        )  
    );
}  
add_action( 'init', 'themes_taxonomy');

0
, , CharlyAnderson 4 months 0 Answers 36 views 0

Leave an answer