Proper now, you haven’t any taxonomy rewrite. The taxonomy will attempt to use the taxonomy slug by default however will run right into a battle together with your put up kind slug since they’re each items
. In my instance under, I’ve modified your slugs to higher mirror their origin, then I exploit the rewrite
parameter and has_archive
parameter to outline what the permalinks must be.
// Customized put up sorts GIFTS
operate gifts_post_type(){
$args = array(
'labels' => array(
'identify' => 'Presents',
'singular_name' => 'Present',
),
'description' => __( 'Presents' ),
'menu_icon' => 'dashicons-money-alt',
'hierarchical' => false,
'public' => true,
'show_in_rest' => true,
'helps' => array( 'title', 'editor', 'thumbnail' ),
'taxonomies' => array( 'tax_gifts' ), // Added our taxonomy as "supported" - not required.
'has_archive' => 'items', // Defines the put up kind archive as: '/items/'
'rewrite' => array( 'slug' => 'items/merchandise' ), // Defines the only put up permalink as: '/items/merchandise/$post-slug/'
);
// Modified 'items' to 'cpt_gifts' to indicate that it is a Customized Submit Sort (CPT).
register_post_type( 'cpt_gifts', $args );
}
add_action('init','gifts_post_type');
// Customized put up kind GIFTS Taxonomy
operate gifts_taxonomy(){
$args = array(
'labels' => array(
'identify' => 'Departments',
'singular_name' => 'Division',
),
'public' => true,
'hierarchical' => true,
'show_in_rest' => true, // Wanted in order that the field present up within the Block Editor
'rewrite' => array( 'slug' => 'items' ), // Defines our time period archive as: '/items/$term-slug/'
);
// Modified 'items' to 'tax_gifts' to distinguish the put up kind from taxonomy.
register_taxonomy( 'tax_gifts', array( 'cpt_gifts' ), $args );
}
add_action('init','gifts_taxonomy');