WordPress自定义Meta字段未在自定义文章类型Post Editor中显示
WordPress自定义Meta字段编辑器显示异常问题反馈
开发阶段说明
- 目前在WordPress自定义文章类型、自定义Meta字段开发方向经验尚浅,正在系统学习WordPress REST API相关开发内容
- 现阶段编写了一款测试插件,核心功能为注册自定义Meta字段,插件完整代码如下:
/** * @package api_testing * @version 1.0.0 */ /* Plugin Name: API Testing Plugin URI: http://example.com/ Description: The beginning of an awesome plugin Author: Me Version: 1.0.0 Author URI: http://example.com/ */ function generate_press_type() { $labels = array( 'name' => 'Press Articles', 'singular_name' => 'Press', ); $args = array( 'label' => 'Press', 'labels' => $labels, 'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' ), 'taxonomies' => array( 'category', 'post_tag' ), 'hierarchical' => false, 'public' => true, 'capability_type' => 'post', 'show_in_rest' => true, 'rest_base' => 'press-articles', 'rewrite' => true, 'rewrite_slug' => '', ); register_post_type( 'press_article', $args ); $meta_args = array( 'type' => 'string', 'description' => 'source', 'single' => true, 'show_in_rest' => true, ); register_post_meta( 'press_article', 'source', $meta_args ); } add_action( 'init', 'generate_press_type', 0 );
已确认正常的功能点
- 插件激活后,WordPress后台可以正常看到注册的press文章类型,支持正常创建、编辑对应文章内容
- 调用REST接口查询对应文章内容时,注册的自定义Meta字段
source可以正常出现在接口返回的响应载荷中
存在的问题与排查进展
- 预期目标:让
source字段可以直接展示在文章编辑器的编辑界面中 - 异常表现:打开文章编辑器的自定义字段下拉列表,找不到已经注册的
source字段,对应异常操作界面已留存截图 - 排查情况:已对照WordPress官方文档核对所有注册参数,自认为已经覆盖所有要求的必要参数,但问题仍未解决,需要确认是否在注册文章类型或Meta字段时遗漏了关键配置项。
内容的提问来源于stack exchange,提问作者DLateef
相关产品推荐
相关产品推荐

