最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

My custom taxonomy page is leading in 404 page

programmeradmin3浏览0评论
function wporg_register_taxonomy_instructor()
{
    $labels = [
        'name'              => _x('Instructors', 'taxonomy general name'),
'singular_name'     => _x('Instructor', 'taxonomy singular name'),
'search_items'      => __('Search Instructors'),
'all_items'         => __('All Instructors'),
'parent_item'       => __('Parent Instructor'),
'parent_item_colon' => __('Parent Instructor:'),
'edit_item'         => __('Edit Instructor'),
'update_item'       => __('Update Instructor'),
'add_new_item'      => __('Add New Instructor'),
'new_item_name'     => __('New Instructor Name'),
'menu_name'         => __('Instructor'),
];
$args = [
'hierarchical'      => true, // make it hierarchical (like categories)
'labels'            => $labels,
'show_ui'           => true,
'show_admin_column' => true,
'query_var'         => true,
'rewrite'           => ['slug' => 'instructor'],
];
register_taxonomy('instructor', ['post'], $args);
}
add_action('init', 'wporg_register_taxonomy_instructor');

I use this code to register a custom taxonomy with name instructor but when I click at the link that is produced by get_term_link($term->term_id) I am leading to 404 page.

function wporg_register_taxonomy_instructor()
{
    $labels = [
        'name'              => _x('Instructors', 'taxonomy general name'),
'singular_name'     => _x('Instructor', 'taxonomy singular name'),
'search_items'      => __('Search Instructors'),
'all_items'         => __('All Instructors'),
'parent_item'       => __('Parent Instructor'),
'parent_item_colon' => __('Parent Instructor:'),
'edit_item'         => __('Edit Instructor'),
'update_item'       => __('Update Instructor'),
'add_new_item'      => __('Add New Instructor'),
'new_item_name'     => __('New Instructor Name'),
'menu_name'         => __('Instructor'),
];
$args = [
'hierarchical'      => true, // make it hierarchical (like categories)
'labels'            => $labels,
'show_ui'           => true,
'show_admin_column' => true,
'query_var'         => true,
'rewrite'           => ['slug' => 'instructor'],
];
register_taxonomy('instructor', ['post'], $args);
}
add_action('init', 'wporg_register_taxonomy_instructor');

I use this code to register a custom taxonomy with name instructor but when I click at the link that is produced by get_term_link($term->term_id) I am leading to 404 page.

Share Improve this question asked Apr 5, 2020 at 21:36 Pexle ChrisPexle Chris 313 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You have to re-save the permalinks when you add or change a custom taxonomy, or a custom post type.

Go to the permalinks settings page, and re-save, then go back and refresh.

Also, you don't need to specify the slug as instructor if the name is instructor, the rewrite option can be removed or just set to true

发布评论

评论列表(0)

  1. 暂无评论