admin管理员组文章数量:1278920
I created a custom post type and custom taxonomy.
I can access archive page for this custom post type, showing all entries for this type, but I am unable to get url for a specific taxonomy term.
When I access URL /
I get archive.php
template and all chat entries are listed, but when I access (which is actually the URL shown in my wp-admin for this chat-category) I get a 404 and
archive.php
template wasn't even called. Also, creating template taxonomy-chat-category.php
didn't work and I got also a 404.
Is there a correct URL for a specific category/term in a custom taxonomy?
The solution I can think of is adding a query var like ?chat-category=category-1
and modify the query in archive.php
if this var is present, but I would rather prefer som nice and friendly URL solution.
This is my code:
$labels = [
'name' => _x( 'Categorías de chat', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Categoría de chat', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Buscar categorías de chat', 'textdomain' ),
'all_items' => __( 'Todas las categorías de chat', 'textdomain' ),
'parent_item' => __( 'Categoría de chat padre', 'textdomain' ),
'parent_item_colon' => __( 'Categoría de chat padre:', 'textdomain' ),
'edit_item' => __( 'Editar categoría de chat', 'textdomain' ),
'update_item' => __( 'Actualizar categoría de chat', 'textdomain' ),
'add_new_item' => __( 'Nueva categoría de chat', 'textdomain' ),
'new_item_name' => __( 'Nuevo nombre de categoría de chat', 'textdomain' ),
'menu_name' => __( 'Categoría de chat', 'textdomain' ),
];
$args = [
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'chat-category' ),
];
register_taxonomy('chat-category', ['chat'], $args );
unset($args);
$args = [
'labels' => ['name' => __( 'chats' ),
'singular_name' => __( 'chat' )
],
'can_export' => true,
'capability_type' => 'post',
'custom-fields' => true,
'exclude_from_search' => false,
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => 'dashicons-video-alt2',
'menu_position' => 2,
'public' => true,
'publicly_queryable' => true,
'taxonomies' => ['chat-category'],
'rewrite' => ['slug' => 'chat'],
'supports' => [ 'author', 'title', 'editor', 'thumbnail', 'comments'],
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
];
register_post_type( 'chat', $args);
I created a custom post type and custom taxonomy.
I can access archive page for this custom post type, showing all entries for this type, but I am unable to get url for a specific taxonomy term.
When I access URL http://example/chat/
I get archive.php
template and all chat entries are listed, but when I access http://example/chat-category/category-1
(which is actually the URL shown in my wp-admin for this chat-category) I get a 404 and archive.php
template wasn't even called. Also, creating template taxonomy-chat-category.php
didn't work and I got also a 404.
Is there a correct URL for a specific category/term in a custom taxonomy?
The solution I can think of is adding a query var like ?chat-category=category-1
and modify the query in archive.php
if this var is present, but I would rather prefer som nice and friendly URL solution.
This is my code:
$labels = [
'name' => _x( 'Categorías de chat', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Categoría de chat', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Buscar categorías de chat', 'textdomain' ),
'all_items' => __( 'Todas las categorías de chat', 'textdomain' ),
'parent_item' => __( 'Categoría de chat padre', 'textdomain' ),
'parent_item_colon' => __( 'Categoría de chat padre:', 'textdomain' ),
'edit_item' => __( 'Editar categoría de chat', 'textdomain' ),
'update_item' => __( 'Actualizar categoría de chat', 'textdomain' ),
'add_new_item' => __( 'Nueva categoría de chat', 'textdomain' ),
'new_item_name' => __( 'Nuevo nombre de categoría de chat', 'textdomain' ),
'menu_name' => __( 'Categoría de chat', 'textdomain' ),
];
$args = [
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'chat-category' ),
];
register_taxonomy('chat-category', ['chat'], $args );
unset($args);
$args = [
'labels' => ['name' => __( 'chats' ),
'singular_name' => __( 'chat' )
],
'can_export' => true,
'capability_type' => 'post',
'custom-fields' => true,
'exclude_from_search' => false,
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => 'dashicons-video-alt2',
'menu_position' => 2,
'public' => true,
'publicly_queryable' => true,
'taxonomies' => ['chat-category'],
'rewrite' => ['slug' => 'chat'],
'supports' => [ 'author', 'title', 'editor', 'thumbnail', 'comments'],
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
];
register_post_type( 'chat', $args);
Share
Improve this question
asked Nov 3, 2021 at 11:51
user761076user761076
1057 bronze badges
1 Answer
Reset to default 0Well, after a permalinks options reset (saving permalink options again) turns out that url http://example/chat-category/category-1
is working correctly.
本文标签: Archive page URL for custom taxonomy and post type
版权声明:本文标题:Archive page URL for custom taxonomy and post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741235580a2362945.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论