在 "编辑文章 "的管理页面中显示自定义分类法。

问题描述 投票:0回答:1

我使用下面的代码创建了一个自定义分类法。一切工作几乎完美,这个是创建的。它可以在管理侧菜单中使用,也可以在文章列表页的快速版中使用.但是,我在 "编辑文章 "管理页中没有它(至于类别和标签)。

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

我可以尝试着解决这个问题?

wordpress taxonomy custom-taxonomy wp-admin
1个回答
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 block builder界面,而不是经典的wysiwyg界面(在文章编辑页面),那么在声明自定义文章类型时必须使用相同的参数。

© www.soinside.com 2019 - 2024. All rights reserved.