Simple URLs including taxonomies
-
I have custom post type called
books
. This has a category taxonomy, calledbook_types
. So, for example:Books -> Fiction -> Da Vinci Code
– Custom Post Type: Books
– Custom Taxonomy: Book Types (fiction, non fiction, etc)
– Single entry: Da Vinci CodeI use the Custom Post Type Permalinks plugin as recommended in this forum. So I would have the permalinks structure to be:
/books/fiction#da-vinci-code /books/non-fiction#art-of-war ....
This means the taxonomy template is the important one. So I have a template:
taxonomy-book_types.php
But this doesn’t work. WP gives a 404. What am I missing? My code to create the CPT and Taxonomy is below. And yes, I have flushed the Permalinks many times. What precise settings are needed:
1. In CPT for the post type “books”
2. In CPT for post type taxonomy (categ) called “book_types”
3. In the CPT Permalinks plugin for this section?/** * Post Type: Books. */ $labels = [ "name" => __( "Books", "custom-post-type-ui" ), "singular_name" => __( "Book", "custom-post-type-ui" ), ]; $args = [ "label" => __( "Books", "custom-post-type-ui" ), "labels" => $labels, "public" => true, "publicly_queryable" => true, "show_ui" => true, "show_in_rest" => true, "rest_base" => "", "rest_controller_class" => "WP_REST_Posts_Controller", "has_archive" => true, "show_in_menu" => true, "show_in_nav_menus" => true, "delete_with_user" => false, "exclude_from_search" => false, "capability_type" => "post", "map_meta_cap" => true, "hierarchical" => false, "can_export" => true, "rewrite" => [ "slug" => "books", "with_front" => true ], "query_var" => true, "menu_position" => 5, "menu_icon" => "dashicons-schedule", "supports" => [ "title", "editor" ], "taxonomies" => [ "book_types" ], "show_in_graphql" => false, ]; register_post_type( "books", $args ); /** * Taxonomy: Book Types. */ $labels = [ "name" => __( "Book Types", "custom-post-type-ui" ), "singular_name" => __( "Book Type", "custom-post-type-ui" ), ]; $args = [ "label" => __( "Book Types", "custom-post-type-ui" ), "labels" => $labels, "public" => true, "publicly_queryable" => true, "hierarchical" => true, "show_ui" => true, "show_in_menu" => true, "show_in_nav_menus" => true, "query_var" => true, "rewrite" => [ 'slug' => 'book_types', 'with_front' => true, ], "show_admin_column" => true, "show_in_rest" => true, "show_tagcloud" => false, "rest_base" => "book_types", "rest_controller_class" => "WP_REST_Terms_Controller", "show_in_quick_edit" => false, "sort" => false, "show_in_graphql" => false, ]; register_taxonomy( "book_types", [ "books" ], $args );
- The topic ‘Simple URLs including taxonomies’ is closed to new replies.