I have looked around noth in StackOverflow and WP.SE.
Like many before me, I just want this structure
mysite.com/custom-post-type/custom-taxonomy-term/post-name
Or, in other words,
mysite.com/publication/book/post-name (single post)
mysite.com/publication/book/ (all posts in the term 'book')
mysite.com/publication/ (all posts in this publication CPT)
I followed this instruction by TheDeadMedic for making custom post type with custom taxonomy permalink, and another one by Matthew Boynes to fix the pagination issue.
All works well, except... everytime I open the single post, it returns the 404 page.
I have tried opening the Permalink page and setting flush_rewrite_rules()
to no avail. I still can't open the single page.
The only fix that works is if I change the slug in my custom taxonomy to its original form.
So instead of publication
(the rewrite slug for this tax, in accordance to my custom post type name), I would have the default type
(the default slug for this tax). Which would defeat the purpose.
Here is my code:
function cptui_register_my_taxes_type() {
/**
* Taxonomy: Types.
*/
$labels = array(
"name" => __( 'Types', 'mysite' ),
"singular_name" => __( 'Type', 'mysite' ),
"menu_name" => __( 'Types', 'mysite' ),
"all_items" => __( 'All Types', 'mysite' ),
"edit_item" => __( 'Edit Types', 'mysite' ),
"view_item" => __( 'View Type', 'mysite' ),
"update_item" => __( 'Update Type Name', 'mysite' ),
"add_new_item" => __( 'Add New Type', 'mysite' ),
"new_item_name" => __( 'New Type Name', 'mysite' ),
"parent_item" => __( 'Parent Type', 'mysite' ),
"parent_item_colon" => __( 'Parent Type:', 'mysite' ),
"search_items" => __( 'Search Types', 'mysite' ),
"popular_items" => __( 'Popular Types', 'mysite' ),
"separate_items_with_commas" => __( 'Separate Types with commas', 'mysite' ),
"add_or_remove_items" => __( 'Add or remove Types', 'mysite' ),
"choose_from_most_used" => __( 'Choose from the most used Types', 'mysite' ),
"not_found" => __( 'No Types found', 'mysite' ),
"no_terms" => __( 'No types', 'mysite' ),
"items_list_navigation" => __( 'Types list navigation', 'mysite' ),
"items_list" => __( 'Types list', 'mysite' ),
);
$args = array(
"label" => __( 'Types', 'mysite' ),
"labels" => $labels,
"public" => true,
"hierarchical" => true,
"label" => "Types",
"show_ui" => true,
"show_in_menu" => true,
"show_in_nav_menus" => true,
"query_var" => true,
"rewrite" => array( 'slug' => 'publication', 'with_front' => true, 'hierarchical' => true, ),
"show_admin_column" => true,
"show_in_rest" => false,
"rest_base" => "",
"show_in_quick_edit" => true,
);
register_taxonomy( "tyoe", array( "publication" ), $args );
}
add_action( 'init', 'cptui_register_my_taxes_type' );
Is there a way to fix this?