Guest User

Untitled

a guest
Mar 20th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. $this->post_types = array ( 'post', 'location' );
  2.  
  3. foreach( array( 'field_1', 'field_2' ) as $field ) {
  4. register_rest_field( $this->post_types,
  5. $field,
  6. array(
  7. 'get_callback' => array( $this, 'get_post_meta' ),
  8. 'update_callback' => array( $this, 'update_post_meta' ),
  9. 'schema' => null,
  10. )
  11. );
  12. }
  13.  
  14. public function get_post_meta($object, $field_name, $request) {
  15. return get_post_meta( $object['id'], $field_name, true );
  16. }
  17.  
  18. public function update_post_meta($value, $object, $field_name) {
  19. return update_post_meta( $object->ID, $field_name, $value );
  20. }
  21.  
  22. response = await this.wordPress.cv_location().create({
  23. title: article.title,
  24. content: article.content,
  25. status: article.status,
  26. meta: {
  27. field_1: article.field_1,
  28. field_2: article.field_2,
  29. }
  30. });
Add Comment
Please, Sign In to add comment