在“编辑帖子”管理页面中显示自定义分类法

时间:2020-05-17 13:11:54

标签: wordpress taxonomy custom-taxonomy wp-admin

我使用以下代码创建了自定义分类法。一切都几乎完美,这就是创造出来的。在管理端菜单以及文章列表页面的快速版中都可用。 但是,我在“编辑帖子”管理页面中没有它(关于类别和标签):

add_action( 'init', 'create_chapitres_taxo', 0 );
  function create_chapitres_taxo() {
    $labels = array(
      'name' => _x( 'Chapitres', 'taxonomy general name' ),
      'singular_name' => _x( 'Chapitre', 'taxonomy singular name' ),
      'search_items' =>  __( 'Recherche un chapitre' ),
      'popular_items' => __( 'Capitres populaires' ),
      'all_items' => __( 'Toutes les catégories' ),
      'parent_item' => null,
      'parent_item_colon' => null,
      'edit_item' => __( 'Editer la chapitre' ),
      'update_item' => __( 'Editer la chapitre' ),
      'add_new_item' => __( 'Ajouter un chapitre' ),
      'new_item_name' => __( 'Ajouter un chapitre' ),
      'separate_items_with_commas' => __( 'Séparer les chapitres avec une virgule' ),
      'add_or_remove_items' => __( 'Ajouter ou retirer un chapitre' ),
      'choose_from_most_used' => __( 'Choisir le chapitre' ),
      'menu_name' => __( 'Chapitres' ),
    );
    register_taxonomy('chapitre','post',array(
      'hierarchical' => false,
      'labels' => $labels,
      'show_ui' => true,
      'show_admin_column' => true,
      'update_count_callback' => '_update_post_term_count',
      'query_var' => true,
      'rewrite' => array( 'slug' => 'chapitres' ),
    ));
  }

enter image description here

但是

enter image description here

该如何解决?

1 个答案:

答案 0 :(得分:2)

您需要在参数中添加:'show_in_rest' => true,以使其在Gutemberg界面中显示。

因此它将变为:

  register_taxonomy('chapitre','post',array(
  'hierarchical' => false,
  'labels' => $labels,
  'show_in_rest' => true //add this
  'show_ui' => true,
  'show_admin_column' => true,
  'update_count_callback' => '_update_post_term_count',
  'query_var' => true,
  'rewrite' => array( 'slug' => 'chapitres' ),
));

注意:如果需要Gutemberg块生成器界面,而不是经典的wysiwyg(在帖子编辑页面上),则在声明自定义帖子类型时必须使用相同的参数。