content management system - Wordpress custom post type permalink structure for category -
i have custom post type defined taxonomy(category) below code: custom post type archive works fine when try access taxonomy archive 404 page. e.g url: example.com/wordpress-websites/inspiration-category have registered taxonomy name inspiration-category template file im using cpt taxonomy taxonomy-inspiration-category.php
wordpress code:
register_post_type( 'wordpress-websites', array( 'labels' => array( 'name' => __( 'inspirations' ), 'singular_name' => __( 'inspiration' ), 'add_new' => __( 'add new' ), 'add_new_item' => __( 'create new inspiration' ), 'edit' => __( 'edit' ), 'edit_item' => __( 'edit inspiration' ), 'new_item' => __( 'new inspiration' ), 'view' => __( 'view inspirations' ), 'view_item' => __( 'view inspiration' ), 'search_items' => __( 'search inspirations' ), 'not_found' => __( 'no inspirations found' ), 'not_found_in_trash' => __( 'no inspirations found in trash' ), 'parent' => __( 'parent inspiration' ), ), 'description' => __( 'this can create new inspirations on site.' ), 'public' => true, 'has_archive' => true, 'show_ui' => true, 'capability_type' => 'post', 'publicly_queryable' => true, 'exclude_from_search' => false, 'menu_position' => 2, 'menu_icon' => 'dashicons-megaphone' /* get_stylesheet_directory_uri() . '/images/tag_orange.png' */, 'hierarchical' => true, '_builtin' => false, // it's custom post type, not built in! 'rewrite' => array( 'slug' => 'wordpress-websites', 'with_front' => true ), 'query_var' => true, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ), ) ); //hook init action , call create_book_taxonomies when fires add_action( 'init', 'create_product_taxonomies', 0 ); //add_action('admin_init', 'flush_rewrite_rules'); //create 2 taxonomies, genres , writers post type "book" function create_product_taxonomies() { // add new taxonomy, make hierarchical (like categories) $labels = array( 'name' => _x( 'categories', 'taxonomy general name' ), 'singular_name' => _x( 'category', 'taxonomy singular name' ), 'search_items' => __( 'search categories' ), 'all_items' => __( 'all categories' ), 'parent_item' => __( 'parent categories' ), 'parent_item_colon' => __( 'parent categories:' ), 'edit_item' => __( 'edit category' ), 'update_item' => __( 'update category' ), 'add_new_item' => __( 'add new category' ), 'new_item_name' => __( 'new category name' ), 'menu_name' => __( 'category' ), ); register_taxonomy( 'inspiration-category', 'inspiration', array( 'wordpress-websites' ), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'has_archive' => true, //'rewrite' => true, 'rewrite' => array( 'slug' => 'wordpress-websites', 'with_front' => true ), ) ); }
expected url permalinks cpt: example.com/wordpress-websites/ - main archive example.com/wordpress-websites/inspiration-category - category archive
or instead of categories / taxonomy - tags best practise ? , work expected url?
also when use below code in taxonomy, category archive works url structure not recommended includes underscore:
register_taxonomy( 'inspiration_cat', 'inspiration', array( 'wordpress-websites' ), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'has_archive' => 'inspiration', //'rewrite' => true, 'rewrite' => array( 'slug' => 'wordpress-websites', 'with_front' => true ), ) );
for above code use template: taxonomy-inspiration_cat.php works
can me ?
Comments
Post a Comment