I'm working on a WP website with many CPTs and Custom Taxonomies, but also using the regular "post" post type for the regular blog section of the site.
I want the blog posts and archive and categories to have /blog/ in their permalink, but also want to specify permalink structure for the other CPTs without the /blog/ interfering.
for example: I have an "events" CPT, which has a custom taxonomy named "ecat".
Now I got an archive page with permalink sitename.com/events working well
And the single event page has permalink like sitename.com/events/event-name as well.
But the custom taxonomy archive is in sitename.com/ecat/ategory-name. I want the custom taxonomy to have the cpt slug in its permalink like: sitename.com/events/ecat/category-name
Note: I don't want the single event to have the taxonomy term in its permalink.
My CPT registration Code:
$labels = array(
'name' => _x( 'Events', 'Post Type General Name', 'textdomain' ),
'singular_name' => _x( 'Event', 'Post Type Singular Name', 'textdomain' ),
'menu_name' => __( 'Events', 'textdomain' ),
'name_admin_bar' => __( 'Event', 'textdomain' ),
'archives' => __( 'Item Archives', 'textdomain' ),
'attributes' => __( 'Item Attributes', 'textdomain' ),
'parent_item_colon' => __( 'Parent Item:', 'textdomain' ),
'all_items' => __( 'All Items', 'textdomain' ),
'add_new_item' => __( 'Add New Item', 'textdomain' ),
'add_new' => __( 'Add New', 'textdomain' ),
'new_item' => __( 'New Item', 'textdomain' ),
'edit_item' => __( 'Edit Item', 'textdomain' ),
'update_item' => __( 'Update Item', 'textdomain' ),
'view_item' => __( 'View Item', 'textdomain' ),
'view_items' => __( 'View Items', 'textdomain' ),
'search_items' => __( 'Search Item', 'textdomain' ),
'not_found' => __( 'Not found', 'textdomain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'textdomain' ),
'featured_image' => __( 'Featured Image', 'textdomain' ),
'set_featured_image' => __( 'Set featured image', 'textdomain' ),
'remove_featured_image' => __( 'Remove featured image', 'textdomain' ),
'use_featured_image' => __( 'Use as featured image', 'textdomain' ),
'insert_into_item' => __( 'Insert into item', 'textdomain' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'textdomain' ),
'items_list' => __( 'Items list', 'textdomain' ),
'items_list_navigation' => __( 'Items list navigation', 'textdomain' ),
'filter_items_list' => __( 'Filter items list', 'textdomain' ),
);
$args = array(
'label' => __( 'Event', 'textdomain' ),
'description' => __( 'Events custom post type', 'textdomain' ),
'labels' => $labels,
'supports' => array( 'title' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-calendar-alt',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'show_in_rest' => false,
'rewrite' => array( 'slug' => 'events','with_front' => false ),
);
register_post_type( 'events', $args );
My Custom Taxonomy register code:
//Event Categories
$labels = array(
'name' => _x( 'Events Categories', 'textdomain' ),
'singular_name' => _x( 'Events Category', 'textdomain' ),
'menu_name' => __( 'Events Categories', 'textdomain' ),
'all_items' => __( 'All Items', 'textdomain' ),
'parent_item' => __( 'Parent Item', 'textdomain' ),
'parent_item_colon' => __( 'Parent Item:', 'textdomain' ),
'new_item_name' => __( 'New Item Name', 'textdomain' ),
'add_new_item' => __( 'Add New Item', 'textdomain' ),
'edit_item' => __( 'Edit Item', 'textdomain' ),
'update_item' => __( 'Update Item', 'textdomain' ),
'view_item' => __( 'View Item', 'textdomain' ),
'separate_items_with_commas' => __( 'Separate items with commas', 'textdomain' ),
'add_or_remove_items' => __( 'Add or remove items', 'textdomain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'textdomain' ),
'popular_items' => __( 'Popular Items', 'textdomain' ),
'search_items' => __( 'Search Items', 'textdomain' ),
'not_found' => __( 'Not Found', 'textdomain' ),
'no_terms' => __( 'No items', 'textdomain' ),
'items_list' => __( 'Items list', 'textdomain' ),
'items_list_navigation' => __( 'Items list navigation', 'textdomain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => false,
'show_in_rest' => false,
);
register_taxonomy( 'ecat', array( 'events' ), $args );