Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Convert Category Image IDs to URL */
- function tc_register_category_images_field() {
- register_rest_field(
- 'listing',
- 'category-image',
- array(
- 'get_callback' => 'tc_get_category_images_urls',
- 'update_callback' => null,
- 'schema' => null,
- )
- );
- }
- add_action( 'rest_api_init', 'tc_register_category_images_field' );
- function tc_get_category_images_urls( $object, $field_name, $request ) {
- $medium = wp_get_attachment_image_src( get_post_thumbnail_id( $object->id ), 'medium' );
- $medium_url = $medium['0'];
- return array(
- 'medium' => $medium_url,
- );
- }
Add Comment
Please, Sign In to add comment