admin管理员组文章数量:1122846
Hoping for some help... This relates to similar questions but with some variation where I haven't been able to get to a working solution.
What I'm trying to do
- I want to use my created custom taxonomy in the posts permalink structure. Eg: www.example/articles/**%CUSTOM_TAX%**/%postname%/
- I also want to allow for a fallback default custom tax term for instances where a post hasn't yet been assigned to a custom term yet. This covers for all the thousands of posts in the site yet to be assigned to a custom term.
What I've tried
I've tried a number of solutions, the closest I've got is by reregistering the default post and then rewriting the permalink structure, but it feels very messy, and adds a duplicate "Post" link in the menu casuing confusion. Sourced from here: Permalink help with default Posts and custom Taxonomy
I've also tried the following which aren't quite what I need so didn't help:
- Adding Custom Taxonomy to WordPress default Post type
- Custom permalink with child taxonomy terms
My Code
Registering my Custom Taxonomy:
add_action( 'init', function() {
register_taxonomy( 'cog_clinical_tags', array(
0 => 'post',
), array(
'labels' => array(
'name' => 'Clinical Topics',
'singular_name' => 'Clinical Topic',
'menu_name' => 'Clinical Topics',
'all_items' => 'All Clinical Topics',
'edit_item' => 'Edit Clinical Topic',
'view_item' => 'View Clinical Topic',
'update_item' => 'Update Clinical Topic',
'add_new_item' => 'Add New Clinical Topic',
'new_item_name' => 'New Clinical Topic Name',
'search_items' => 'Search Clinical Topics',
'not_found' => 'No clinical topics found',
'no_terms' => 'No clinical topics',
'items_list_navigation' => 'Clinical Topics list navigation',
'items_list' => 'Clinical Topics list',
'back_to_items' => '← Go to clinical topics',
'item_link' => 'Clinical Topic Link',
'item_link_description' => 'A link to a clinical topic',
),
'public' => true,
'hierarchical' => true,
'show_in_menu' => true,
'show_in_rest' => true,
'show_tagcloud' => false,
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'clinical-area',
'with_front' => false,
),
'default_term' => array(
'name' => 'Clinical',
'slug' => 'clinical',
),
) );
} );
Thanks in advance.
本文标签: permalinksUsing Custom Taxonomy in Default Post Slug
版权声明:本文标题:permalinks - Using Custom Taxonomy in Default Post Slug 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736311025a1934590.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论