php - 帖子编辑器中未显示 Wordpress 元字段
问题描述
使用 WP 和自定义元字段有点新。
我正在尝试学习 REST API 并创建了一个插件来注册自定义元字段。这是插件:
/**
* @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 );
我可以在 WP 后端看到类型“press”并创建帖子。当我查询它们时,元字段会显示在有效负载中。我只是想知道是否有可能让该字段显示在帖子编辑器中,我看到了自定义字段列表,但我的不包括在内:
想知道我在注册帖子类型或元数据时是否错过了一个 arg?我查看了文档,似乎我已经拥有了所有内容,但不确定...
解决方案
您必须添加自定义元框才能显示该字段。请在此处查看 - https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/
推荐阅读
- node.js - MongoError:拓扑被破坏,NODEJS
- python - 容器以非零退出代码 143 退出。被外部信号杀死
- python - 如何使用 Python 将一系列重复的数据行转换为多条记录的列?
- java - JMSCMQ0001:WebSphere MQ 调用失败,compcode '2' ('MQCC_FAILED') 原因 '2009' ('MQRC_CONNECTION_BROKEN')
- c++ - 代码使用向量成功运行,但使用数组显示错误
- c++ - 为什么我可以将变量存储在不是其最小对齐倍数的地址?
- python - 如何在 Jupyter Notebook 中运行 GitHub 代码?
- java - 如何在 jaxb XJC 生成期间重命名 xs:simpleType?
- javascript - 如何对空格分隔值进行是的电子邮件验证?
- java - ActiveMQ 消息重新传递延迟不起作用