Guest User

Untitled

a guest
Dec 18th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. add_action( 'rest_api_init', 'create_api_posts_meta_field' );
  2. function create_api_posts_meta_field() {
  3.  
  4. // register_rest_field ( 'name-of-post-type', 'name-of-field-to-return', array-of-callbacks-and-schema() )
  5. register_rest_field( 'parsing', 'parsing_night_key', array(
  6. 'get_callback' => 'get_post_meta_for_api',
  7. 'schema' => null,
  8. )
  9. );
  10. }
  11.  
  12. function get_post_meta_for_api( $object ) {
  13. //get the id of the post object array
  14. $post_id = $object['id'];
  15.  
  16. //return the post meta
  17. return get_post_meta( $post_id );
  18. }
Add Comment
Please, Sign In to add comment