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

  1. I want to use my created custom taxonomy in the posts permalink structure. Eg: www.example/articles/**%CUSTOM_TAX%**/%postname%/
  2. 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