Guest User

Untitled

a guest
Nov 15th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. /* Convert Category Image IDs to URL */
  2. function tc_register_category_images_field() {
  3. register_rest_field(
  4. 'listing',
  5. 'category-image',
  6. array(
  7. 'get_callback' => 'tc_get_category_images_urls',
  8. 'update_callback' => null,
  9. 'schema' => null,
  10. )
  11. );
  12. }
  13.  
  14. add_action( 'rest_api_init', 'tc_register_category_images_field' );
  15.  
  16. function tc_get_category_images_urls( $object, $field_name, $request ) {
  17. $medium = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'medium' );
  18. $medium_url = $medium['0'];
  19.  
  20. return array(
  21. 'medium' => $medium_url,
  22. );
  23. }
Add Comment
Please, Sign In to add comment