Getting a number instead of URL as output for the images with custom field in WP REST API WordPress

Hi I am using WP Rest Api plugin to get api access to my custom fields.
Everything works fine except the output of the images. I am getting a number instead of a URL.

Function.php

Read More
    register_rest_field( 'team',
        'company_logo',
        array(
            'get_callback'    => 'slug_get_field',
            'update_callback' => null,
            'schema'          => null,
            )
        );
}

function slug_get_field( $object, $field_name, $request ) {
    return get_post_meta( $object[ 'id' ], $field_name, true );
}

company_logo is a custom field to an image, made with Custom Content Type Manager.

This is what I am retrieving as JSON.

{
    "id": 10,
    "title": {
      "rendered": "Giel"
    },
    "content": {
      "rendered": ""
    },
    "company_logo": "16",
    "company_bg": "11"
}

Please help thanks!

Related posts

1 comment

  1. I think you need to call

    wp_get_attachment_url() or wp_get_attachment_image_src()
    

    with the object['id'] since this will return the full image url.

Comments are closed.