admin管理员组文章数量:1122846
How to make such a structure for cpt? '/slug/%category%/%category2%/%postname%/' for post '/slug/%category1%/%category2%/' for taxonomy
There will be a maximum of 2 levels of categories. If a post has one category then '/slug/%category%/%postname%/'
I need this kind of structure only for this CPT and Taxonomy.
register_post_type(
'slug_cpt',
array(
'labels' => $labels,
'exclude_from_search' => false,
'has_archive' => true,
'public' => true,
'publicly_queryable' => true,
'rewrite' => true,
'can_export' => true,
'show_in_nav_menus' => true,
'supports' => array('title', 'thumbnail', 'comments', 'page-attributes', 'custom-fields'),
'show_in_rest' =>true,
)
);
register_taxonomy(
'slug_cats',
'slug_cpt',
array(
'hierarchical' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'labels' =>array(),
'query_var' => true,
'show_in_rest' => true,
)
);
How to make such a structure for cpt? '/slug/%category%/%category2%/%postname%/' for post '/slug/%category1%/%category2%/' for taxonomy
There will be a maximum of 2 levels of categories. If a post has one category then '/slug/%category%/%postname%/'
I need this kind of structure only for this CPT and Taxonomy.
register_post_type(
'slug_cpt',
array(
'labels' => $labels,
'exclude_from_search' => false,
'has_archive' => true,
'public' => true,
'publicly_queryable' => true,
'rewrite' => true,
'can_export' => true,
'show_in_nav_menus' => true,
'supports' => array('title', 'thumbnail', 'comments', 'page-attributes', 'custom-fields'),
'show_in_rest' =>true,
)
);
register_taxonomy(
'slug_cats',
'slug_cpt',
array(
'hierarchical' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'labels' =>array(),
'query_var' => true,
'show_in_rest' => true,
)
);
Share
Improve this question
asked Jun 1, 2024 at 19:20
Сергей КонстантиновСергей Константинов
32 bronze badges
1 Answer
Reset to default 0If you use the Advanced Custom Fields plugin (ACF) to create your custom taxonomy for your custom post type then you can just check the box to make it hierarchical. It will then automatically create a url structure matching the hierarchy.
本文标签: url rewritingHow to make such a structure for cpt
版权声明:本文标题:url rewriting - How to make such a structure for cpt? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305248a1932519.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论