Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- register_meta('my_post_type', 'city', [
- 'type' => 'string',
- 'description' => 'Cidade',
- 'single' => true,
- 'show_in_rest' => true
- ]);
- register_meta('post', 'city', [
- 'object_subtype' => 'my_post_type', // Limit to a post type.
- 'type' => 'string',
- 'description' => 'Cidade',
- 'single' => true,
- 'show_in_rest' => true,
- ]);
- register_post_type(
- 'my_post_type',
- array(
- 'supports' => array( 'custom-fields', ... ), // custom-fields is required
- ...
- )
- );
- add_action( 'rest_api_init', function () {
- register_rest_field( 'my_post_type', 'city', array(
- 'get_callback' => function( $post_arr ) {
- return get_post_meta( $post_arr['id'], 'city', true );
- },
- ) );
- } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement