{"id":11950641,"date":"2019-09-19T22:27:04","date_gmt":"2019-09-19T22:27:04","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/cmb2-rest-api-image-file-field-as-an-object\/"},"modified":"2019-09-19T22:27:04","modified_gmt":"2019-09-19T22:27:04","slug":"cmb2-rest-api-image-file-field-as-an-object","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/cmb2-rest-api-image-file-field-as-an-object\/","title":{"rendered":"CMB2 Rest API &#8211; image\/file field as an object"},"content":{"rendered":"<p>Hello,<\/p>\n<p>I&#8217;m using the REST API from CMB2 to build out a headless CMS\/static site, and I&#8217;m running into an issue I can&#8217;t find away around:<\/p>\n<p>The <code>file_list<\/code> field type returns an object of key\/value pairs with the ID of the image as the key. This enables me to hit the wordpress REST API and retrieve each image&#8217;s data (alt_text, width, height, etc). <\/p>\n<p>However, the <code>file<\/code> field type only returns a string. That&#8217;s useful for just displaying the image, but it would be way more useful to also be able to access that file as an object. I can&#8217;t think of a way to do this without having the ID. <\/p>\n<p>Is there any way to have the <code>file<\/code> field output be similar to <code>file_list<\/code>? Something like this?<br \/>\n<code>{&#039;123&#039;: &#039;http:\/\/site.com\/wp-content\/uploads\/image.jpg&#039;}<\/code><\/p>\n","protected":false},"template":"","class_list":["post-11950641","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11950641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/11950641\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=11950641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}