Question

i created a custom taxonomy named cancers and a template file for this taxonomy named taxonomy-cancers.php but when i call this url:

http://localhost/cancers even http://localhost/?tax=cancers

wordpress shows page not found and doesn't use my taxonomy template. this is my code for defining custom taxonomy:

add_action( 'init', 'create_cancers_taxonomy', 0 );
function create_cancers_taxonomy() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name'                   => _x( 'سرطان‌ها', 'taxonomy general name' ),
'singular_name'  => _x( 'سرطان', 'taxonomy singular name' ),
'search_items'   => __( 'جستجو در میان سرطان‌ها' ),
'all_items'              => __( 'تمامی سرطان‌ها' ),
'parent_item'    => __( 'دسته اصلی' ),
'parent_item_colon' => __( 'دسته اصلی:' ),
'edit_item'              => __( 'ویرایش سرطان' ),
'update_item'    => __( 'بروزرسانی سرطان' ),
'add_new_item'   => __( 'افزودن سرطان' ),
'new_item_name'  => __( 'عنوان سرطان' ),
'menu_name'              => __( 'سرطان‌ها' ),
);
$args = array(
'hierarchical'   => true,
'labels'                 => $labels,
'show_ui'                => true,
'show_admin_column' => true,
'query_var'              => true,
);
register_taxonomy( 'cancers', array('cancer', 'post'), $args );
}
Was it helpful?

Solution

I think you forgot to add rewrite parameter in arguments,

Use this arguments:--

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'cancers' ),
);

Note:- After changing this, please update your Permalinks from Settings --> Permalinks once...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top