Skip to content

Instantly share code, notes, and snippets.

@kadamwhite
Created January 11, 2018 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadamwhite/e60fcb233b5120e8d3b1e9c0b472c3b0 to your computer and use it in GitHub Desktop.
Save kadamwhite/e60fcb233b5120e8d3b1e9c0b472c3b0 to your computer and use it in GitHub Desktop.

register_meta and the REST API

In the year since 4.8, confusion about how to properly expose meta information through the REST API has been one of the most prevalend issues we've seen in support posts and tickets.

Most developers try to use register_meta with show_in_rest => true; unfortunately register_meta works on object types, not subtypes, so you cannot pass a custom post type name into register_meta like you can with register_rest_field. Worse, if you register meta for the type 'post', then that meta key is registered not just for core posts, but for every single custom post type. Meta almost never applies across all post types, so this behavior forces developers to use register_rest_field for REST API data modeling instead of taking advantage of the API's built-in meta handling.

there is no way to and this behavior makes it impossible for a developer to register meta that is specific to their single post type. and requires any REST API data modeling to use register_rest_field instead of register_meta.

Despite discussion about adding a subtype argument this got backed out of

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment