a little new to working with WP and Custom Meta Fields.
I'm trying to learn REST API and created a plugin to register a custom metafield. This is the plugin:
/**
* @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 );
I can see type "press" in the WP backend and create posts. When I query them the metafield shows up in the payload. I'm just wondering if its possible to get the field to show up in the Post editor, I see the list of custom fields but mine is not included:
Wonder if I missed an arg when registering either the post type or the meta? I looked at the docs and it seems I've got everything there but not sure...
You have to add custom metabox to show the field. Please check here - https://developer.wordpress.org/plugins/metadata/custom-meta-boxes/