【问题标题】:Showing custom taxonomy in the "edit post" admin page在“编辑帖子”管理页面中显示自定义分类
【发布时间】:2020-05-17 13:11:54
【问题描述】:

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

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' ),
    ));
  }

但是

我可以尝试什么来解决这个问题?

【问题讨论】:

    标签: wordpress taxonomy custom-taxonomy wp-admin


    【解决方案1】:

    您需要在参数中添加:'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 块构建器界面,而不是经典的所见即所得(在帖子编辑页面上)。

    【讨论】:

    • 非常感谢我只是忘记了这个参数! ...这是古腾堡的新作品吗?
    • 是的,所以分类也可以在 WP REST API 中使用。如果一切正常,请将此标记为答案:) 谢谢,祝你好运
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 2018-08-29
    相关资源
    最近更新 更多