Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. register_meta('my_post_type', 'city', [
  2. 'type' => 'string',
  3. 'description' => 'Cidade',
  4. 'single' => true,
  5. 'show_in_rest' => true
  6. ]);
  7.  
  8. register_meta('post', 'city', [
  9. 'object_subtype' => 'my_post_type', // Limit to a post type.
  10. 'type' => 'string',
  11. 'description' => 'Cidade',
  12. 'single' => true,
  13. 'show_in_rest' => true,
  14. ]);
  15.  
  16. register_post_type(
  17. 'my_post_type',
  18. array(
  19. 'supports' => array( 'custom-fields', ... ), // custom-fields is required
  20. ...
  21. )
  22. );
  23.  
  24. add_action( 'rest_api_init', function () {
  25. register_rest_field( 'my_post_type', 'city', array(
  26. 'get_callback' => function( $post_arr ) {
  27. return get_post_meta( $post_arr['id'], 'city', true );
  28. },
  29. ) );
  30. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement