[wp-trac] [WordPress Trac] #39803: REST API meta type not working properly for custom post types
WordPress Trac
noreply at wordpress.org
Tue Feb 7 05:11:01 UTC 2017
#39803: REST API meta type not working properly for custom post types
--------------------------+-----------------------------
Reporter: chriseverson | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 4.7
Severity: normal | Keywords:
Focuses: rest-api |
--------------------------+-----------------------------
When attempting to set meta via a custom post types api endpoint, the meta
type is always set to `post`. This results in all meta updates for custom
post types via the REST API failing.
For example:
{{{#!php
$args = [
'type' => 'string',
'single' => true,
'show_in_rest' => true
];
register_meta( 'book', 'author', $args );
}}}
If I'm understanding correctly, the above should expose the 'author' meta
to the REST API. However, in the REST API, all of these fail due to a
check against `WP_REST_Post_Meta_Fields->get_registered_fields()`.
`WP_REST_Post_Meta_Fields->get_registered_fields()` in turn matches meta
keys to `get_registered_meta_keys( $this->get_meta_type() )` which always
returns `post`.
Not sure if any of that makes sense...
The fix would be to make `WP_REST_Post_Meta_Fields->get_meta_type()`
return the post type as far as I can tell.
I would love to tackle this one, however I wanted to get some input from
someone more well-versed in the REST API codebase before tackling this to
be sure that there isn't a reason that
`WP_REST_Post_Meta_Fields->get_meta_type()` is explicitly set to return
`post`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39803>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list