How to add a custom taxonomy to a custom post type's document tab

I created a custom taxonomy and wanted to add it to the side-menu of my portfolio custom post type (in the admin area).

I created a custom taxonomy and wanted to add it to the side-menu of my portfolio custom post type (in the admin area). My custom taxonomy is not loading, but the default one ('category') does. What did I miss?

add_action( 'init', 'add_taxonomies' );    
function add_taxonomies() {
    register_taxonomy(
      'related_service',
      'portfolio',
      array(
        'label' => 'Related Services',
        'public' => true
      )
    );
  }

add_action( 'init', 'register' );
    function register() {
      register_post_type( 'portfolio', array(
        'label' => 'Portfolio',
        'public' => true,
        'show_in_rest' => true,
        'taxonomies'  => array( 'category', 'related_service' )
      ) );
    }

I created a custom taxonomy and wanted to add it to the side-menu of my portfolio custom post type (in the admin area). My custom taxonomy is not loading, but the default one ('category') does. What did I miss?

add_action( 'init', 'add_taxonomies' );    
function add_taxonomies() {
    register_taxonomy(
      'related_service',
      'portfolio',
      array(
        'label' => 'Related Services',
        'public' => true
      )
    );
  }

add_action( 'init', 'register' );
    function register() {
      register_post_type( 'portfolio', array(
        'label' => 'Portfolio',
        'public' => true,
        'show_in_rest' => true,
        'taxonomies'  => array( 'category', 'related_service' )
      ) );
    }
Share Improve this question edited Dec 11, 2019 at 23:22 Rob Monhemius asked Dec 11, 2019 at 22:04 Rob MonhemiusRob Monhemius 2032 silver badges6 bronze badges 5
  • besides the double ")" on the first line, your code works well on a fresh installation of WordPress. – Kaperto Commented Dec 11, 2019 at 22:21
  • The missing ")" in the question has been corrected. For clarity, I want to be able to select a category in the document tab on the right hand side when a portfolio CPT is opened. I only see that functionality for Categories in my installation. – Rob Monhemius Commented Dec 11, 2019 at 22:34
  • 3 If you're using the Block Editor you also need to add 'show_in_rest' => true for the taxonomy. You only have it for the CPT currently. – WebElaine Commented Dec 11, 2019 at 22:36
  • 1 @WebElaine If you add it as an answer I will mark it as the correct answer, thank you :). – Rob Monhemius Commented Dec 11, 2019 at 22:41
  • @WebElaine can you post your answer as an answer so I can upvote it? – Tom J Nowell Commented Dec 11, 2019 at 23:24
Add a comment  | 

1 Answer 1

Reset to default 0

If you're using the Block Editor you also need to add 'show_in_rest' => true for the taxonomy. You only have it for the CPT currently.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744911157a4600559.html

相关推荐

  • How to add a custom taxonomy to a custom post type's document tab

    I created a custom taxonomy and wanted to add it to the side-menu of my portfolio custom post type (in the admin area).

    2天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信