问题描述
我正在尝试学习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”并创建帖子。当我查询它们时,元字段会显示在有效负载中。我只是想知道是否有可能使该字段显示在Post编辑器中,我看到了自定义字段的列表,但我的列表不包括在内:
想知道在注册帖子类型或元时是否错过了arg吗?我看了看文档,似乎所有东西都在那里,但不确定...
解决方法
您必须添加自定义元框才能显示该字段。请在此处检查-https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/