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
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!
I think you need to call
with the
object['id']
since this will return the full image url.