[wp-trac] [WordPress Trac] #38786: register_meta()'s show_in_rest not mapping to specific fields
WordPress Trac
noreply at wordpress.org
Mon Nov 14 16:40:14 UTC 2016
#38786: register_meta()'s show_in_rest not mapping to specific fields
--------------------------+-----------------------------
Reporter: garubi | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Keywords:
Focuses: rest-api |
--------------------------+-----------------------------
I'm following the directions found on the (future) documentation for the
REST API https://github.com/WP-API/wp-api-meta-endpoints/blob/new-meta-
new-life/README.md#apispecific-options.
Reading it, looks like we could register any custom field to be exposed
via REST API and map it to an API-specific field name.
i.e the field could be "telephone_number" but exposed to the API as
"phone".
{{{
function register_new_meta() {
$args = array(
//'sanitize_callback' => 'sanitize_my_meta_key',
//'auth_callback' => 'authorize_my_meta_key',
'type' => 'string',
'description' => 'test register_field',
'single' => true,
'show_in_rest' => array(
'name' => 'phone'
)
register_meta( 'post', 'telephone_number', $args );
}
}}}
I tested it and in the response to my GET I get the 'phone' field empty,
while if I omit the 'name' => 'phone' argument, setting only show_in_rest
=> true like this:
{{{
add_action( 'init', 'register_new_meta');
function register_new_meta() {
$args = array(
'type' => 'string',
'description' => 'Extra information',
'single' => true,
'show_in_rest' => true,
);
register_meta( 'post', 'telephone_number', $args );
}
}}}
I get the 'wpcf-informazioni' field populated with its content.
So is the "mapping" to the "name" not working (maybe the document I
referenced isn't updated), or am I doing something wrong... ?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38786>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list