I have custom post type 'coupons':
$args = array(
'label' => __('Купоны', 'sp'),
'labels' => $labels,
'supports' => array('title', 'custom-fields', 'revisions', 'thumbnail', 'excerpt'),
'hierarchical' => true,
'public' => false,
'show_ui' => true,
'menu_position' => 2,
'show_in_admin_bar' => true,
'has_archive' => true,
'capability_type' => 'post',
'rewrite' => array('slug' => 'coupons', 'with_front' => false)
);
register_post_type('coupons', $args);
I have custom taxonomy 'sategory':
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'sategory',
'with_front' => false),
);
register_taxonomy('sategory', array('coupons'), $args);
When i open "example.com/sategory/tax1" 404 error. File taxonomy-sategory.php created. What could be the problem?
CodePudding user response:
To expand upon what @KrunalBhimajiyani said, whenever you create a CPT or taxonomy, or edit those in a way that the URL structure would change, you need to “flush the permalinks”.
For performance reasons the URL mapping code is cached and doesn’t change unless an admin manually updates it. This can be done simply by performing any one of these:
- Going to the Settings, Permalinks admin page and pressing the noted “Save” button without making any changes
- Conditionally calling
flush_rewrite_rules
when a change happens (Not always! You need to either just remove it when done or store a version key or similar in options.) - Using the WP-CLI command:
wp rewrite flush
(optionally with the--hard
parameter